Skip to content

Fix compilation under cython 3. #41530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/cython-3.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 15 additions & 5 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this adapts to the letter of the deprecation but not the spirit?

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")


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down