From 11e90d85321b1b4437e8383e651a92c5ef753b72 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Wed, 29 Nov 2023 01:24:11 +0530 Subject: [PATCH 1/3] pin cython<3.0 to avoid performance regression --- pyproject.toml | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 63220a0..b53d030 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,6 @@ requires = [ "wheel>=0.29.0", "setuptools>=42.0.0", "oldest-supported-numpy", - "Cython>=0.20", + "Cython<3.0", "mako" ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index afbee6f..64cd771 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Cython>=0.20 +Cython<3.0 setuptools>=6.0 numpy mako diff --git a/setup.py b/setup.py index 51cfa10..fe1a5d2 100644 --- a/setup.py +++ b/setup.py @@ -87,7 +87,7 @@ def setup_package(): # The requirements. install_requires = [ - 'numpy', 'mako', 'Cython>=0.20', 'setuptools>=6.0' + 'numpy', 'mako', 'Cython<3.0', 'setuptools>=6.0' ] tests_require = ["pytest"] docs_require = ["sphinx"] From 4ea3fe0b678fac0d2a43796ea9087fc544450bad Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Wed, 29 Nov 2023 01:33:44 +0530 Subject: [PATCH 2/3] Revert "fix(cyarray.pyx.mako): resetting ndarray.data" This reverts commit 3d7fb6729d9e27260efab9236ac144a308c1d1ee. Since, cython is pinned to be <3.0, this is no longer required. --- cyarray/carray.pyx | 22 +++++----------------- cyarray/carray.pyx.mako | 14 +------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/cyarray/carray.pyx b/cyarray/carray.pyx index 14e3c67..213ebc8 100644 --- a/cyarray/carray.pyx +++ b/cyarray/carray.pyx @@ -65,18 +65,6 @@ cdef extern from "numpy/arrayobject.h": cdef extern from "stdlib.h": void *memcpy(void *dst, void *src, long n) nogil - -# Cython>= 3.0 now disallows relpacing the guts of a numpy array. -# Workaround: Thanks https://github.com/rainwoodman/pandas/blob/05d3fe2402e4563124e7060837ded7513ab5bca7/pandas/_libs/reduction.pyx#L27 # noqa: E501 -# FIXME: FIND A CLEANER SOLUTION -cdef extern from *: - """ - static void PyArray_SET_DATA(PyArrayObject *arr, char * data) { - arr->data = data; - } - """ - void PyArray_SET_DATA(np.ndarray arr, char * data) nogil - # numpy module initialization call _import_array() @@ -463,7 +451,7 @@ cdef class IntArray(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array @@ -968,7 +956,7 @@ cdef class UIntArray(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array @@ -1473,7 +1461,7 @@ cdef class LongArray(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array @@ -1978,7 +1966,7 @@ cdef class FloatArray(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array @@ -2483,7 +2471,7 @@ cdef class DoubleArray(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array diff --git a/cyarray/carray.pyx.mako b/cyarray/carray.pyx.mako index 29f70ef..30208be 100644 --- a/cyarray/carray.pyx.mako +++ b/cyarray/carray.pyx.mako @@ -73,18 +73,6 @@ cdef extern from "numpy/arrayobject.h": cdef extern from "stdlib.h": void *memcpy(void *dst, void *src, long n) nogil - -# Cython>= 3.0 now disallows relpacing the guts of a numpy array. -# Workaround: Thanks https://github.com/rainwoodman/pandas/blob/05d3fe2402e4563124e7060837ded7513ab5bca7/pandas/_libs/reduction.pyx#L27 # noqa: E501 -# FIXME: FIND A CLEANER SOLUTION -cdef extern from *: - """ - static void PyArray_SET_DATA(PyArrayObject *arr, char * data) { - arr->data = data; - } - """ - void PyArray_SET_DATA(np.ndarray arr, char * data) nogil - # numpy module initialization call _import_array() @@ -475,7 +463,7 @@ cdef class ${CLASSNAME}(BaseArray): if self._old_data != NULL: self.data = self._old_data self._old_data = NULL - PyArray_SET_DATA(self._npy_array, self.data) + self._npy_array.data = self.data cdef void c_resize(self, long size) nogil: cdef PyArrayObject* arr = self._npy_array From a5d054de9a57b5e7ebbcf3a17dd4fef220b29594 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Wed, 29 Nov 2023 01:38:05 +0530 Subject: [PATCH 3/3] ci(gha): update action and python versions --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 37e13b3..0e4c992 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,12 +7,12 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: [3.7, 3.8, 3.9] + python-version: ['3.9', '3.10', '3.11'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: