From fa6cc2247cb17d0d0375c62250b32d3dfbe47bf0 Mon Sep 17 00:00:00 2001 From: Graeme Watt Date: Mon, 15 May 2017 16:56:27 +0100 Subject: [PATCH] oldhepdata: allow absence of "location", "description", or record_ids * Write absence of "location" or "description" as empty strings instead of None. * Check for presence of "description" before deciding whether to reformat matrix based on words in description. * Fix bug writing record_id if key but not value given in original file. * Bump version to 0.1.30. Signed-off-by: Graeme Watt --- hepdata_converter/parsers/__init__.py | 4 ++-- hepdata_converter/parsers/oldhepdata_parser.py | 7 ++++--- hepdata_converter/version.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hepdata_converter/parsers/__init__.py b/hepdata_converter/parsers/__init__.py index 12f704e..0485601 100644 --- a/hepdata_converter/parsers/__init__.py +++ b/hepdata_converter/parsers/__init__.py @@ -40,8 +40,8 @@ def __init__(self, index=None, data_file=None, table_name=None, metadata=None, d self.metadata = metadata or { 'name': table_name or 'Table %s' % self.index, - 'location': None, - 'description': None, + 'location': '', + 'description': '', 'keywords': [ {'name': 'reactions', 'values': []}, {'name': 'observables', 'values': []}, diff --git a/hepdata_converter/parsers/oldhepdata_parser.py b/hepdata_converter/parsers/oldhepdata_parser.py index 78eb3d8..cd5297e 100644 --- a/hepdata_converter/parsers/oldhepdata_parser.py +++ b/hepdata_converter/parsers/oldhepdata_parser.py @@ -388,8 +388,9 @@ def _parse_table_data(self, data): energy = energy_min self._parse_energies(energy) - if any(word in self.current_table.description.lower() for word in ['covariance', 'correlation', 'matrix']): - reformatted = self._reformat_matrix() + if self.current_table.description: + if any(word in self.current_table.description.lower() for word in ['covariance', 'correlation', 'matrix']): + reformatted = self._reformat_matrix() def _reformat_matrix(self): """Transform a square matrix into a format with two independent variables and one dependent variable. @@ -656,7 +657,7 @@ def _parse_record_ids(self, data): if 'record_ids' not in self.data[0]: self.data[0]['record_ids'] = [] - record_id = {'type': key, 'id': int(data)} + record_id = {'type': key, 'id': int(data) if data else 0} if self.data[0]['record_ids'].count(record_id) == 0: self.data[0]['record_ids'].append(record_id) diff --git a/hepdata_converter/version.py b/hepdata_converter/version.py index f722485..2b3687d 100644 --- a/hepdata_converter/version.py +++ b/hepdata_converter/version.py @@ -1,3 +1,3 @@ # this file ideally should only contain __version__ declaration, as anything else # may break setup.py and PyPI uploads -__version__ = '0.1.29' +__version__ = '0.1.30'