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

Change nan fallback in MOS Table to avoid JSON Serialization Warning #1958

Merged
merged 5 commits into from
Jan 25, 2023

Conversation

duytnguyendtn
Copy link
Collaborator

Description

Our traitlet messaging infrastructure does not support nans in the payload, as they are not JSON serializable. I changed the default fallback for missing RA/Dec values from nan to our default Unspecified we use for the Filter and Grating. Unfortunately this means it's a string rather than a float, and thereby a different type, but oh well.

I also add a preemptive sanitization check in _add_to_table to convert any nans to string 'nan's in case the user actually provides a nan directly. The issue/slightly controversial step here is the need to add pandas to our dependencies to actually perform the nan check. numpy.isnan doesn't support complex objects and will spit an error, as opposed to pandas.isna. We can debate whether we want this or not; I can easily remove it

Fixes #

Change log entry

  • Is a change log needed? If yes, is it added to CHANGES.rst? If you want to avoid merge conflicts,
    list the proposed change log here for review and add to CHANGES.rst before merge. If no, maintainer
    should add a no-changelog-entry-needed label.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@codecov
Copy link

codecov bot commented Jan 6, 2023

Codecov Report

Base: 91.93% // Head: 91.94% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (1afa569) compared to base (d9e71d6).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1958   +/-   ##
=======================================
  Coverage   91.93%   91.94%           
=======================================
  Files         140      140           
  Lines       15310    15314    +4     
=======================================
+ Hits        14076    14081    +5     
+ Misses       1234     1233    -1     
Impacted Files Coverage Δ
...daviz/configs/imviz/tests/test_astrowidgets_api.py 98.58% <100.00%> (+<0.01%) ⬆️
jdaviz/configs/mosviz/helper.py 87.47% <100.00%> (+0.08%) ⬆️
jdaviz/configs/mosviz/plugins/parsers.py 89.83% <100.00%> (ø)
jdaviz/core/freezable_state.py 91.66% <100.00%> (+1.38%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

I'm not sure exactly how to test this, but it looks like it does the job.

@duytnguyendtn
Copy link
Collaborator Author

As per discussion with the team, the included nan-check didn't seem worth the additional dependency, so I removed the check and rebased. This should be ready for rereview!

@duytnguyendtn duytnguyendtn requested a review from pllim January 25, 2023 17:00
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Simple and elegant. Thanks!

@pllim pllim added this to the 3.2.1 milestone Jan 25, 2023
@pllim pllim added bug Something isn't working 💤 backport-v3.2.x on-merge: backport to v3.2.x labels Jan 25, 2023
@pllim
Copy link
Contributor

pllim commented Jan 25, 2023

Is a change log needed? I am on the fence.

@pllim
Copy link
Contributor

pllim commented Jan 25, 2023

Ooops... looks like this affects tested behavior:

ValueError: 'Unspecified' did not parse as unit: At col 0, Unspecified is not a valid unit.

@pllim
Copy link
Contributor

pllim commented Jan 25, 2023

Probably wanna add extra logic to return None, None in this check for your new values:

ra = table_data["R.A."][msg.selected_index]
dec = table_data["Dec."][msg.selected_index]

@duytnguyendtn
Copy link
Collaborator Author

Tests are passing! (Just pushed up a changelog, but nothing in the code changed). Thanks for the assist @pllim!

CHANGES.rst Outdated Show resolved Hide resolved
Co-authored-by: P. L. Lim <[email protected]>
@pllim
Copy link
Contributor

pllim commented Jan 25, 2023

You got 2 approvals, so feel free to merge when CI is green. 😸

@duytnguyendtn duytnguyendtn merged commit fe9dcf3 into spacetelescope:main Jan 25, 2023
@duytnguyendtn
Copy link
Collaborator Author

Thanks for the eyes!

@lumberbot-app
Copy link

lumberbot-app bot commented Jan 25, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.2.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 fe9dcf30822e2d8d2a87d07a9701513f6e110785
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #1958: Change nan fallback in MOS Table to avoid JSON Serialization Warning'
  1. Push to a named branch:
git push YOURFORK v3.2.x:auto-backport-of-pr-1958-on-v3.2.x
  1. Create a PR against branch v3.2.x, I would have named this PR:

"Backport PR #1958 on branch v3.2.x (Change nan fallback in MOS Table to avoid JSON Serialization Warning)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@duytnguyendtn
Copy link
Collaborator Author

Grr... auto backport failed. Do we care enough to manually backport?

@pllim
Copy link
Contributor

pllim commented Jan 25, 2023

I am neutral... 😬

@pllim pllim mentioned this pull request Feb 7, 2023
9 tasks
@pllim pllim modified the milestones: 3.2.1, 3.3 Feb 7, 2023
@pllim pllim removed 💤 backport-v3.2.x on-merge: backport to v3.2.x Still Needs Manual Backport labels Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mosviz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants