diff --git a/CHANGES.rst b/CHANGES.rst index ce227a9d..fef5c8da 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ================ diff --git a/conftest.py b/conftest.py index b81c77d8..2c83886e 100644 --- a/conftest.py +++ b/conftest.py @@ -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. diff --git a/pyvo/dal/query.py b/pyvo/dal/query.py index beedd97f..2bb187ad 100644 --- a/pyvo/dal/query.py +++ b/pyvo/dal/query.py @@ -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): """ diff --git a/pyvo/dal/tests/test_query.py b/pyvo/dal/tests/test_query.py index 177d4d53..bed62bf5 100644 --- a/pyvo/dal/tests/test_query.py +++ b/pyvo/dal/tests/test_query.py @@ -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( diff --git a/pyvo/registry/rtcons.py b/pyvo/registry/rtcons.py index 262e94d6..0f37db65 100644 --- a/pyvo/registry/rtcons.py +++ b/pyvo/registry/rtcons.py @@ -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()) diff --git a/pyvo/registry/tests/test_rtcons.py b/pyvo/registry/tests/test_rtcons.py index 86467d05..79e78a21 100644 --- a/pyvo/registry/tests/test_rtcons.py +++ b/pyvo/registry/tests/test_rtcons.py @@ -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 @@ -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, @@ -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()