diff --git a/.github/workflows/cython-3.yml b/.github/workflows/cython-3.yml new file mode 100644 index 0000000000000..6b453414d3f2f --- /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 diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index c28db9b669a4b..5f78c9b167946 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -24,6 +24,16 @@ 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 +350,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 +479,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 +500,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/setup.py b/setup.py index 386074519ca4f..82d6803406b18 100755 --- a/setup.py +++ b/setup.py @@ -375,7 +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} +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