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

BUG: fix float string literal issues #624

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading