Skip to content

Commit b40494d

Browse files
Merge pull request #146 from DunklesArchipel/source-data-fields
Fix plotting with option `original`
2 parents eb4dfda + 8795a31 commit b40494d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

doc/news/source-data-fields.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**Fixed:**
2+
3+
* Fixed plotting with option `original` if the fields contain fields without units.

unitpackage/database/echemdb_entry.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,24 @@ def rescale(self, units):
324324
{'name': 'E', 'type': 'number', 'unit': 'V', 'reference': 'RHE'},
325325
{'name': 'j', 'type': 'number', 'unit': 'mA / cm2'}]
326326
327+
Unitless fields in ``figureDescription.fields`` (e.g., ``cycle``)
328+
are skipped during rescaling (For testing purposes we add here a
329+
field without units to the datapackage)::
330+
331+
>>> entry = EchemdbEntry.create_example()
332+
>>> entry.resource.custom["metadata"]["echemdb"]["figureDescription"]["fields"].append({"name": "cycle", "type": "number"})
333+
>>> rescaled_entry = entry.rescale(units='original')
334+
>>> rescaled_entry.fields # doctest: +NORMALIZE_WHITESPACE
335+
[{'name': 't', 'type': 'number', 'unit': 's'},
336+
{'name': 'E', 'type': 'number', 'unit': 'V', 'reference': 'RHE'},
337+
{'name': 'j', 'type': 'number', 'unit': 'mA / cm2'}]
338+
327339
"""
328340
if units == "original":
329341
units = {
330-
field["name"]: field["unit"] for field in self.figureDescription.fields
342+
field["name"]: field["unit"]
343+
for field in self.figureDescription.fields
344+
if hasattr(field, "unit")
331345
}
332346

333347
return super().rescale(units)

0 commit comments

Comments
 (0)