Skip to content

Commit

Permalink
Merge pull request #137 from mhvk/numpy-2.0-compat
Browse files Browse the repository at this point in the history
Numpy 2.0 compat
  • Loading branch information
mhvk committed Mar 3, 2024
2 parents eb1c732 + 5c260ef commit 7847a2f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions erfa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from .ufunc import get_leap_seconds, set_leap_seconds, dt_eraLEAPSECOND


NUMPY_LT_2_0 = np.__version__.startswith("1.")

_NotFound = object()


Expand Down Expand Up @@ -269,8 +271,8 @@ def validate(cls, table):
if hasattr(table, '__array__'):
table = table.__array__()[list(dt_eraLEAPSECOND.names)]

table = np.array(table, dtype=dt_eraLEAPSECOND, copy=False,
ndmin=1)
table = np.array(table, dtype=dt_eraLEAPSECOND, ndmin=1,
copy=False if NUMPY_LT_2_0 else None)

# Simple sanity checks.
if table.ndim > 1:
Expand Down
9 changes: 7 additions & 2 deletions erfa/ufunc.c.templ
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ static int ErfaUFuncTypeResolver(PyUFuncObject *ufunc,
{
int *types;
PyArray_Descr **dtypes;
int types_array[NPY_MAXARGS];

/* This array needs to be at least as long as nint+nout. In practice, 32 suffices */
int types_array[32];

if (ufunc->userloops) {
Py_ssize_t unused_pos = 0;
Expand Down Expand Up @@ -752,7 +754,10 @@ PyMODINIT_FUNC PyInit_ufunc(void)
PyArray_Descr *dt_ymdf = NULL, *dt_hmsf = NULL, *dt_dmsf = NULL;
PyArray_Descr *dt_sign = NULL, *dt_type = NULL;
PyArray_Descr *dt_eraASTROM = NULL, *dt_eraLDBODY = NULL;
PyArray_Descr *dtypes[NPY_MAXARGS];

/* This array needs to be at least as long as nint+nout. In practice, 32 suffices */
PyArray_Descr *dtypes[32];

/* ufuncs and their definitions */
int status;
PyUFuncObject *ufunc;
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ deps =
extras =
test

install_command =
!devdeps: python -I -m pip install
devdeps: python -I -m pip install -v --pre

commands =
pip freeze
python -c 'import erfa' # To give useful error message if liberfa is too old.
Expand Down

0 comments on commit 7847a2f

Please sign in to comment.