Skip to content

Commit

Permalink
Merge pull request astropy#636 from bsipocz/str_query_params
Browse files Browse the repository at this point in the history
MAINT: moving the str input validation out to avoid astropy deprecation
  • Loading branch information
bsipocz authored Jan 15, 2025
2 parents 0a380cd + d1fa2bb commit a0ab0e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions pyvo/dal/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,12 @@ def _validate_pos(self, pos):
self._validate_ra(m)

def _validate_ra(self, ra):
if not isinstance(ra, Quantity):
ra = ra * u.deg
ra = Quantity(ra, u.deg)
if ra.to(u.deg).value < 0 or ra.to(u.deg).value > 360.0:
raise ValueError(f'Invalid ra: {ra}')

def _validate_dec(self, dec):
if not isinstance(dec, Quantity):
dec = dec * u.deg
dec = Quantity(dec, u.deg)
if dec.to(u.deg).value < -90.0 or dec.to(u.deg).value > 90.0:
raise ValueError(f'Invalid dec: {dec}')

Expand Down Expand Up @@ -415,10 +413,11 @@ def get_dal_format(self, val):
low, high))
if self._unit:
if not isinstance(low, Quantity):
low = low * self._unit
low = u.Quantity(low, self._unit)
low = low.to(self._unit, equivalencies=self._equivalencies).value

if not isinstance(high, Quantity):
high = high * self._unit
high = Quantity(high, self._unit)
high = high.to(self._unit, equivalencies=self._equivalencies).value

if low > high:
Expand Down
6 changes: 3 additions & 3 deletions pyvo/dal/tests/test_adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TestClass(dict, AxisParamMixin):

# errors
test_obj.pos.pop()
with pytest.raises(ValueError):
with pytest.raises(TypeError):
test_obj.pos.add(('A', 2, 3))
with pytest.raises(ValueError):
test_obj.pos.add((-2, 7, 3))
Expand Down Expand Up @@ -116,7 +116,7 @@ class TestClass(dict, AxisParamMixin):
test_obj.band.add(())
with pytest.raises(ValueError):
test_obj.band.add((1, 2, 3))
with pytest.raises(ValueError):
with pytest.raises(TypeError):
test_obj.band.add(('INVALID', 6))
with pytest.raises(ValueError):
test_obj.band.add((3, 1))
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_soda_query():
assert not hasattr(test_obj, '_range')

# error cases
with pytest.raises(ValueError):
with pytest.raises(TypeError):
test_obj.circle = ('A', 1, 2)
with pytest.raises(ValueError):
test_obj.circle = (1, 1, 2, 2)
Expand Down

0 comments on commit a0ab0e9

Please sign in to comment.