Skip to content

Commit

Permalink
numpy compat fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Aug 16, 2024
1 parent 47e04e5 commit 6a255fa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ jobs:
os: ubuntu-latest
pyver: cp39-cp39
piparch: manylinux2010_x86_64
numpy: numpy==2.0.1
cython: Cython==3.0.10
numpy: numpy==1.19.3
cython: Cython==0.29.23

- name: linux 3.10 amd64
os: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_numpy_include_dirs():
'ply', # for asLib
]

if numpy.lib.NumpyVersion(numpy.__version__) >= '2.0.0b1':
if hasattr(numpy.lib, "NumpyVersion") and numpy.lib.NumpyVersion(numpy.__version__) >= '2.0.0b1':
install_requires += ['numpy >= 1.7', 'numpy < 3']
else:
# assume ABI forward compatibility as indicated by
Expand Down
6 changes: 2 additions & 4 deletions src/p4p.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
#endif

// avoid numpy deprecation warnings when building with cython >= 3.0
#if CYTHON_HEX_VERSION>=0x03000000
# define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
# define NPY_TARGET_VERSION NPY_1_7_API_VERSION
#endif
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#define NPY_TARGET_VERSION NPY_1_7_API_VERSION

namespace p4p {

Expand Down
4 changes: 2 additions & 2 deletions src/pvxs_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ PyObject* asPy(const Value& v, bool unpackstruct, bool unpackrecurse, PyObject*

PyRef pyarr(PyArray_New(&PyArray_Type, 1, &shape, ntype, nullptr,
const_cast<void*>(varr.data()), // should not actually be modifiable
esize, NPY_CARRAY_RO, nullptr));
esize, NPY_ARRAY_CARRAY_RO, nullptr));

#ifdef PyArray_SetBaseObject
PyArray_SetBaseObject((PyArrayObject*)pyarr.obj, holder.release());
Expand Down Expand Up @@ -530,7 +530,7 @@ void storePy(Value& v, PyObject* py, bool forceCast)
}

PyRef arr(PyArray_FromAny(py, PyArray_DescrFromType(ntype), 0, 0,
NPY_CARRAY_RO|NPY_ARRAY_FORCECAST, nullptr));
NPY_ARRAY_CARRAY_RO|NPY_ARRAY_FORCECAST, nullptr));

if(PyArray_NDIM((PyArrayObject*)arr.obj)!=1)
throw std::logic_error("Only 1-d array can be assigned");
Expand Down

0 comments on commit 6a255fa

Please sign in to comment.