Skip to content

Commit

Permalink
oldhepdata: allow absence of "location", "description", or record_ids
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
GraemeWatt committed May 15, 2017
1 parent 69f57c0 commit fa6cc22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions hepdata_converter/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': []},
Expand Down
7 changes: 4 additions & 3 deletions hepdata_converter/parsers/oldhepdata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hepdata_converter/version.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit fa6cc22

Please sign in to comment.