From 05d3fe2402e4563124e7060837ded7513ab5bca7 Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Mon, 17 May 2021 15:19:14 -0700 Subject: [PATCH 1/6] Fix compilation under cython 3. --- pandas/_libs/reduction.pyx | 19 ++++++++++++++----- pandas/_libs/util.pxd | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index c28db9b669a4b..974922cda59f2 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -23,6 +23,15 @@ from pandas._libs.util cimport ( from pandas._libs.lib import is_scalar +# Accessing the data member of ndarray is deprecated, but we depend on it. +cdef extern from *: + """ + static void PyArray_SET_DATA(PyArrayObject *arr, void * data) { + arr->data = data; + } + """ + void PyArray_SET_DATA(ndarray arr, void * data) + cdef cnp.dtype _dtype_obj = np.dtype("object") @@ -340,18 +349,18 @@ cdef class Slider: self.stride = values.strides[0] self.orig_data = self.buf.data - self.buf.data = self.values.data + PyArray_SET_DATA(self.buf, self.values.data) self.buf.strides[0] = self.stride cdef move(self, int start, int end): """ For slicing """ - self.buf.data = self.values.data + self.stride * start + PyArray_SET_DATA(self.buf, self.values.data + self.stride * start) self.buf.shape[0] = end - start cdef reset(self): - self.buf.data = self.orig_data + PyArray_SET_DATA(self.buf, self.orig_data) self.buf.shape[0] = 0 @@ -469,7 +478,7 @@ cdef class BlockSlider: arr = self.blk_values[i] # axis=1 is the frame's axis=0 - arr.data = self.base_ptrs[i] + arr.strides[1] * start + PyArray_SET_DATA(arr, self.base_ptrs[i] + arr.strides[1] * start) arr.shape[1] = end - start # move and set the index @@ -490,7 +499,7 @@ cdef class BlockSlider: arr = self.blk_values[i] # axis=1 is the frame's axis=0 - arr.data = self.base_ptrs[i] + PyArray_SET_DATA(arr, self.base_ptrs[i]) arr.shape[1] = 0 cdef _restore_blocks(self): diff --git a/pandas/_libs/util.pxd b/pandas/_libs/util.pxd index bd1e21b0d8665..a646ca895a060 100644 --- a/pandas/_libs/util.pxd +++ b/pandas/_libs/util.pxd @@ -1,7 +1,7 @@ cimport numpy as cnp from numpy cimport ndarray -from pandas._libs.tslibs.util cimport * +from .tslibs.util cimport * cdef extern from "numpy/ndarraytypes.h": From 4f301137c0e187b9b9b0acc2c778a452fb76efaa Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Mon, 17 May 2021 16:21:37 -0700 Subject: [PATCH 2/6] revert pandas._libs removal --- pandas/_libs/util.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/util.pxd b/pandas/_libs/util.pxd index a646ca895a060..bd1e21b0d8665 100644 --- a/pandas/_libs/util.pxd +++ b/pandas/_libs/util.pxd @@ -1,7 +1,7 @@ cimport numpy as cnp from numpy cimport ndarray -from .tslibs.util cimport * +from pandas._libs.tslibs.util cimport * cdef extern from "numpy/ndarraytypes.h": From 88d6839e23d08291ca3aef7502aa414dd56726b3 Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Tue, 18 May 2021 11:24:20 -0700 Subject: [PATCH 3/6] Workaround https://github.com/cython/cython/issues/4172 --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 386074519ca4f..1ea7374f8c51c 100755 --- a/setup.py +++ b/setup.py @@ -375,7 +375,12 @@ def run(self): # Note: if not using `cythonize`, coverage can be enabled by # pinning `ext.cython_directives = directives` to each ext in extensions. # github.com/cython/cython/wiki/enhancements-compilerdirectives#in-setuppy -directives = {"linetrace": False, "language_level": 3} +directives = {"linetrace": False, + "language_level": 3, + # Use cython 0.29.x binop methods. + # See https://github.com/cython/cython/issues/4172 + "c_api_binop_methods": True, + } macros = [] if linetrace: # https://pypkg.com/pypi/pytest-cython/f/tests/example-project/setup.py From 3000692d24c3a759786b2a1edc624b91a486d59b Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Tue, 18 May 2021 11:31:41 -0700 Subject: [PATCH 4/6] Add github workflow for testing on cython 3(alpha) --- .github/workflows/cython-3.yml | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/cython-3.yml diff --git a/.github/workflows/cython-3.yml b/.github/workflows/cython-3.yml new file mode 100644 index 0000000000000..9e831c7d160f5 --- /dev/null +++ b/.github/workflows/cython-3.yml @@ -0,0 +1,70 @@ +name: Cython 3 + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + name: actions-310-dev + timeout-minutes: 60 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python Dev Version + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + pip install git+https://github.com/numpy/numpy.git + pip install git+https://github.com/pytest-dev/pytest.git + pip install git+https://github.com/nedbat/coveragepy.git + pip install cython=3.0a6 python-dateutil pytz hypothesis pytest-xdist + pip list + + - name: Build Pandas + run: | + python setup.py build_ext -q -j2 + python -m pip install -e . --no-build-isolation --no-use-pep517 + + - name: Build Version + run: | + python -c "import pandas; pandas.show_versions();" + + - name: Test with pytest + run: | + coverage run -m pytest -m 'not slow and not network and not clipboard' pandas + continue-on-error: true + + - name: Publish test results + uses: actions/upload-artifact@master + with: + name: Test results + path: test-data.xml + if: failure() + + - name: Print skipped tests + run: | + python ci/print_skipped.py + + - name: Report Coverage + run: | + coverage report -m + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + flags: unittests + name: codecov-pandas + fail_ci_if_error: true From cccdfd7308cd5cef21528828580f6ba9de08f906 Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Wed, 19 May 2021 10:26:59 -0700 Subject: [PATCH 5/6] fix format with pre-commit command. --- pandas/_libs/reduction.pyx | 1 + setup.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 974922cda59f2..5f78c9b167946 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -23,6 +23,7 @@ from pandas._libs.util cimport ( from pandas._libs.lib import is_scalar + # Accessing the data member of ndarray is deprecated, but we depend on it. cdef extern from *: """ diff --git a/setup.py b/setup.py index 1ea7374f8c51c..82d6803406b18 100755 --- a/setup.py +++ b/setup.py @@ -375,12 +375,13 @@ def run(self): # Note: if not using `cythonize`, coverage can be enabled by # pinning `ext.cython_directives = directives` to each ext in extensions. # github.com/cython/cython/wiki/enhancements-compilerdirectives#in-setuppy -directives = {"linetrace": False, - "language_level": 3, - # Use cython 0.29.x binop methods. - # See https://github.com/cython/cython/issues/4172 - "c_api_binop_methods": True, - } +directives = { + "linetrace": False, + "language_level": 3, + # Use cython 0.29.x binop methods. + # See https://github.com/cython/cython/issues/4172 + "c_api_binop_methods": True, +} macros = [] if linetrace: # https://pypkg.com/pypi/pytest-cython/f/tests/example-project/setup.py From b9ddb29c28b7f324a2e0b5e2df92ca3077e85679 Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Wed, 19 May 2021 10:27:18 -0700 Subject: [PATCH 6/6] update pip install syntax. --- .github/workflows/cython-3.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cython-3.yml b/.github/workflows/cython-3.yml index 9e831c7d160f5..6b453414d3f2f 100644 --- a/.github/workflows/cython-3.yml +++ b/.github/workflows/cython-3.yml @@ -30,7 +30,7 @@ jobs: pip install git+https://github.com/numpy/numpy.git pip install git+https://github.com/pytest-dev/pytest.git pip install git+https://github.com/nedbat/coveragepy.git - pip install cython=3.0a6 python-dateutil pytz hypothesis pytest-xdist + pip install cython==3.0a6 python-dateutil pytz hypothesis pytest-xdist pip list - name: Build Pandas