Skip to content
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

Check for nan dateobs before converting to Time #550

Merged
merged 1 commit into from
May 22, 2024

Conversation

duytnguyendtn
Copy link
Contributor

@duytnguyendtn duytnguyendtn commented May 17, 2024

This small PR fixes #549 by adding an additional check on the ucd value of VOX:Image_MJDateObs before trying to construct an astropy.Time object. Bug found in SIA, though this PR ALSO preemptively performs the same check for SSA's ssa:DataID.Date.

Changelog will be added immediately after this PR is published, and a PR number is assigned

@duytnguyendtn
Copy link
Contributor Author

Just saw @ManonMarchand tagged this to the 1.5.2 bugfix milestone. Didn't see an entry for this version, so I moved my changelog entry to a new 1.5.2 header. Feel free to edit if I didn't quite get it right!

@ManonMarchand
Copy link
Member

Awesome, thanks!

Would you be comfortable adding a test? A suggestion on how to proceed could be :

  • edit test/data/sia/dataset.xml to add a second record with a nan
  • add a test on _test_result in the sia tests

And it would also be nice to rebase the commits on the changlelog to group them together. If you need help with this don't hesitate to ask.

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this now to get it into the bugfix release.

All looks good, thanks for the PR and the review!

@bsipocz bsipocz merged commit 96b0f7a into astropy:main May 22, 2024
10 checks passed
bsipocz added a commit that referenced this pull request May 22, 2024
Check for nan dateobs before converting to Time
bsipocz added a commit that referenced this pull request May 22, 2024
Check for nan dateobs before converting to Time
Comment on lines +700 to +705
try:
if not dateobs or np.isnan(dateobs):
return None
except TypeError:
# np.isnan can only check floats. If can't check for nan, pass it along
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @bsipocz beat me to the punch before I could say anything! Thanks for the merge!

Some small context behind the try except on why I moved the check nan check to this try except, When testing I ran into this same error on stackoverflow: https://stackoverflow.com/questions/52657223/typeerror-ufunc-isnan-not-supported-for-the-input-types-and-the-inputs-could

Since the suggestion was to use pandas which isn't a current dependency for pyvo, I figured it was too much weight just for this small test to add a whole new dep. So the intention was to have np.isnan check the conditions it is able to, but to allow anything outside of those bounds to flow through to Time as before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looked good, the comment in the code seemed sufficient, and you addressed the review requests, too, so no more explanation is needed.

And indeed, we would have asked you to write a workaround if you introduced pandas as a dependency here.

@duytnguyendtn duytnguyendtn deleted the time_nan branch May 22, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PyVO dateobs attribute not handling NaNs
3 participants