Skip to content

Commit

Permalink
Merge pull request #624 from bsipocz/BUG_np_repr
Browse files Browse the repository at this point in the history
BUG: fix float string literal issues
  • Loading branch information
bsipocz authored Nov 25, 2024
2 parents 99e0fd9 + eba8c6f commit 2bf4e3f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Bug Fixes

- Fix propagating some previously swallowed exceptions. [#614]

- Fix string literal generation for SQL query when using numpy >=2.0. [#624]


1.6 (2024-11-01)
================
Expand Down
5 changes: 0 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
iers_conf.auto_download = False


# Keep this until we require numpy to be >=2.0
if minversion(np, "2.0.0.dev0+git20230726"):
np.set_printoptions(legacy="1.25")


def pytest_configure(config):
"""Configure Pytest with Astropy.
Expand Down
2 changes: 1 addition & 1 deletion pyvo/dal/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def __len__(self):
return len(self._mapping)

def __repr__(self):
return repr(tuple(self.values()))
return repr(tuple(f'{val}' for val in self.values()))

def get(self, key, default=None, decode=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyvo/dal/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_repr(self):
record = DALResults.from_result_url(
'http://example.com/query/basic')[0]
truth = 'Illuminatus'
assert repr(record) == repr((23, truth))
assert repr(record) == repr(('23', truth))

def test_get(self):
record = DALResults.from_result_url(
Expand Down
7 changes: 2 additions & 5 deletions pyvo/registry/rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ def make_sql_literal(value):
elif isinstance(value, bytes):
return "'{}'".format(value.decode("ascii").replace("'", "''"))

elif isinstance(value, (int, numpy.integer)):
return "{:d}".format(value)

elif isinstance(value, (float, numpy.floating)):
return repr(value)
elif isinstance(value, (int, numpy.integer, float, numpy.floating)):
return f'{value}'

elif isinstance(value, datetime.datetime):
return "'{}'".format(value.isoformat())
Expand Down
8 changes: 6 additions & 2 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from astropy.coordinates import SkyCoord
from astropy.utils.exceptions import AstropyDeprecationWarning

import numpy
import numpy as np
import pytest

from pyvo import registry
Expand All @@ -21,6 +21,10 @@
from .commonfixtures import messenger_vocabulary, FAKE_GAVO, FAKE_PLAIN # noqa: F401


# We should make sure non-legacy numpy works as expected for string literal generation
np.set_printoptions(legacy=False)


def _build_regtap_query_with_fake(
*args,
service=FAKE_GAVO,
Expand Down Expand Up @@ -52,7 +56,7 @@ class _WithFillers(rtcons.Constraint):
"bytes": b"keep this ascii for now",
"anInt": 210,
"aFloat": 5e7,
"numpyStuff": numpy.float64(23.7),
"numpyStuff": np.float64(23.7),
"timestamp": datetime.datetime(2021, 6, 30, 9, 1), }

return _WithFillers()._get_sql_literals()
Expand Down

0 comments on commit 2bf4e3f

Please sign in to comment.