-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
MAINT: moving the str input validation out to avoid astropy deprecation #636
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #636 +/- ##
==========================================
- Coverage 82.31% 82.30% -0.01%
==========================================
Files 72 72
Lines 7429 7427 -2
==========================================
- Hits 6115 6113 -2
Misses 1314 1314 ☔ View full report in Codecov by Sentry. |
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.
A few comments, feeling responsible for the problems I caused!
pyvo/dal/params.py
Outdated
@@ -367,12 +367,16 @@ def _validate_pos(self, pos): | |||
self._validate_ra(m) | |||
|
|||
def _validate_ra(self, ra): | |||
if isinstance(ra, str): | |||
ra = Unit(ra) |
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.
I think this will go wrong, since you now have a unit and then in the next clause multiply with u.deg
, which keeps it a unit, and I think ra.to(u.deg).value
will go wrong too (though I'm not sure how this ever could have worked??
I think the whole routine could just be
def _validate_ra(self, ra):
ra = Quantity(ra, u.deg)
if not (0 <= ra.value <= 360):
raise ...
This will even support strings like "1.0 arcmin" (but not a simply unit string like "arcmin", which I think is correct).
pyvo/dal/params.py
Outdated
@@ -414,9 +418,13 @@ def get_dal_format(self, val): | |||
raise ValueError('Invalid interval: min({}) > max({})'.format( | |||
low, high)) | |||
if self._unit: | |||
if isinstance(low, str): |
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.
Here, again, converting to a unit seems wrong. One can just do low = Quantity(low)
, assuming that the string contains a unit too (otherwise, it is going to be dimensionless).
211c190
to
d1fa2bb
Compare
Thanks @mhvk for the review! I would still like to have one of the other pyvo maintainers to have a look in case I missed a SODA case, something we should be able to handle but don't in fact support. |
This fixes the branch new astropy deprecation warnings. We only had the string input checked for cases where it should raise an exception, but there could be some cases where it's part of a valid input.
@andamian wrote the original code, so I would like to hear if he is OK with this workaround or have something else in mind instead (I mean this is not a nice workaround).