-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quickfix for numpy.types as meta indicators #30
Conversation
The tests all seem to pass in the GHA, so what exactly is not working with |
The tests only pass because of the (very not elegant) casting in setitem. And I’m sure they would fail if we added numpy.float to the tests… Proposal: anyone recommends a more pythonic approach to the casting (or something else), then I implement it and add tests for other numpy types. |
This question seems to be very relevant here. if isinstance(value, np.generic):
value = value.item() This approach should catch all simple data types, but might not work for if isinstance(value, np.generic):
value = value.tolist() Or maybe, this could even be a single line: value = getattr(value, "tolist", lambda: value)() Here, |
Thanks @glatterf42, followed one of your suggestions... I also added handling of For explanation, having a dictionary with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the requested deletions, this looks good to me. Just one clarifying question: is it enough to test np.float64
or should we investigate why np.float128
is not working and fix that?
Sorry, removed the print statements. About numpy.float128, this is converted to a longdouble, wich then creates issues in the database layer. And numpy.float32 is not "precise", writing 13 to the db and reading it again returns 12.9... Given that pandas uses float64 internally as a default, this PR is good enough for proceeding with the pyam integration. We can tackle more cases once it's necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, looks good to me, then :)
d947e9b
to
f52b938
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR implements a quick-fix when setting meta-indicators with numpy-types, as are used in pd.DataFrames. The PR also improves handling of
None
, so that these values are ignored when setting from a dictionaryrun.meta = {"key": None}
and are used as "delete" when using the setter likerun.meta["key"] = None
.