Conversation
|
Involved with the PRs
|
| if units_key in self.data.keys() and self.data[units_key] is not None: | ||
| dataset.attrs["units"] = self.data[units_key] | ||
| units = self.data.get(units_key, None) | ||
| units = str(units) if isinstance(units, pint.Unit) else units |
There was a problem hiding this comment.
Why not use the pint.UnitRegistry (like in NOMAD)? See how I am using it in the pynxtools-xps here.
There was a problem hiding this comment.
Actually, using just if isinstance(units, pint.Unit) does not seem to work.
If I do the following
import pint
units = "m"
print(isinstance(units, pint.Unit))
that prints False, so obviously this unit check does not work as intended.
pint.Unit is just a class to implement a unit, not something to be used directly to check a string is a pint unit. We need to use pint.UnitRegistry, like in NOMAD.
e6eb16e to
bf3f4fb
Compare
lukaspie
left a comment
There was a problem hiding this comment.
@RubelMozumder I rebased this branch on top of master to make it reviewable.
I don't think your check if isinstance(units, pint.Unit) works, see below.
| if units_key in self.data.keys() and self.data[units_key] is not None: | ||
| dataset.attrs["units"] = self.data[units_key] | ||
| units = self.data.get(units_key, None) | ||
| units = str(units) if isinstance(units, pint.Unit) else units |
There was a problem hiding this comment.
Actually, using just if isinstance(units, pint.Unit) does not seem to work.
If I do the following
import pint
units = "m"
print(isinstance(units, pint.Unit))
that prints False, so obviously this unit check does not work as intended.
pint.Unit is just a class to implement a unit, not something to be used directly to check a string is a pint unit. We need to use pint.UnitRegistry, like in NOMAD.
91e624d to
fb0a864
Compare
| ureg.Unit(units) | ||
| except pint.errors.UndefinedUnitError as exc: | ||
| massage = ( | ||
| f"Units provided for path: '{path}@units' are not valid." |
There was a problem hiding this comment.
| f"Units provided for path: '{path}@units' are not valid." | |
| f"Units '{units}' provided for path: '{path}@units' are not valid." |
| try: | ||
| ureg.Unit(units) | ||
| except pint.errors.UndefinedUnitError as exc: | ||
| massage = ( |
There was a problem hiding this comment.
| massage = ( | |
| message = ( |
| f"Units provided for path: '{path}@units' are not valid." | ||
| f" Please provide a valid unit." | ||
| ) | ||
| raise InvalidDictProvided(massage) from exc |
There was a problem hiding this comment.
Shall this raise an error or simply be logged as a warning? The file can be written without this wrong unit, right?
| raise InvalidDictProvided(massage) from exc | |
| logger.warning(message, exc_info=True) |
|
@RubelMozumder I think we can close this as we anyway already check the units in the validation |
|
@RubelMozumder this PR is sitting here for a while now, it was suggested for closure with reasonable arguments. Is there an update on this? The PR should not be left dangling. |
|
Unable to reproduce the issue. |
No description provided.