From 5f11f9644be2cdd4d0d2bc81c61b07daf33af88b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 11 Aug 2020 13:34:12 -0400 Subject: [PATCH 1/3] Revert "PKG: Set max pin for Cython (#35396)" This reverts commit d3343d9e7f2aa93572d73335a1cc489db267d1ee. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f6f8081b6c464..09f401e949977 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "setuptools", "wheel", - "Cython>=0.29.16,<3", # Note: sync with setup.py + "Cython>=0.29.16", # Note: sync with setup.py "numpy==1.16.5; python_version=='3.7' and platform_system!='AIX'", "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'", "numpy==1.16.5; python_version=='3.7' and platform_system=='AIX'", From 0663a978553cb5876fa472a2f66e471bdc8111ec Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 11 Aug 2020 13:34:27 -0400 Subject: [PATCH 2/3] MNT: do not use deprecated unicode functions Support for the new functions was exposed in cython 0.29.21 --- pandas/_libs/writers.pyx | 4 ++-- pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/writers.pyx b/pandas/_libs/writers.pyx index 40c39aabb7a7a..918b150dc8b99 100644 --- a/pandas/_libs/writers.pyx +++ b/pandas/_libs/writers.pyx @@ -2,7 +2,7 @@ import cython from cython import Py_ssize_t from cpython.bytes cimport PyBytes_GET_SIZE -from cpython.unicode cimport PyUnicode_GET_SIZE +from cpython.unicode cimport PyUnicode_GET_LENGTH import numpy as np @@ -144,7 +144,7 @@ cpdef inline Py_ssize_t word_len(object val): Py_ssize_t l = 0 if isinstance(val, str): - l = PyUnicode_GET_SIZE(val) + l = PyUnicode_GET_LENGTH(val) elif isinstance(val, bytes): l = PyBytes_GET_SIZE(val) diff --git a/pyproject.toml b/pyproject.toml index 09f401e949977..b17a53dd2909a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "setuptools", "wheel", - "Cython>=0.29.16", # Note: sync with setup.py + "Cython>=0.29.21", # Note: sync with setup.py "numpy==1.16.5; python_version=='3.7' and platform_system!='AIX'", "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'", "numpy==1.16.5; python_version=='3.7' and platform_system=='AIX'", diff --git a/setup.py b/setup.py index 43d19d525876b..8d1cee4bbf6a6 100755 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ def is_platform_mac(): min_numpy_ver = "1.16.5" -min_cython_ver = "0.29.16" # note: sync with pyproject.toml +min_cython_ver = "0.29.21" # note: sync with pyproject.toml try: import Cython From 85f2442a5f8b86e6744b8ac3ee211db634955f23 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 11 Aug 2020 13:37:14 -0400 Subject: [PATCH 3/3] WIP: attempt to fix accessing read-only attributes in sliders --- pandas/_libs/reduction.pyx | 42 +++++++++----------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 7b36bc8baf891..0fc8d537d1ecb 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -294,9 +294,8 @@ cdef class Slider: Only handles contiguous data for now """ cdef: - ndarray values, buf - Py_ssize_t stride, orig_len, orig_stride - char *orig_data + ndarray values, buf, orig_data + Py_ssize_t stride def __init__(self, ndarray values, ndarray buf): assert values.ndim == 1 @@ -309,25 +308,17 @@ cdef class Slider: self.buf = buf self.stride = values.strides[0] - self.orig_data = self.buf.data - self.orig_len = self.buf.shape[0] - self.orig_stride = self.buf.strides[0] - - self.buf.data = self.values.data - self.buf.strides[0] = self.stride + self.orig_data = self.buf[:] + self.buf = self.values[::self.stride] cdef move(self, int start, int end): """ For slicing """ - self.buf.data = self.values.data + self.stride * start - self.buf.shape[0] = end - start + self.buf = self.values[start:end:self.stride] cdef reset(self): - - self.buf.shape[0] = self.orig_len - self.buf.data = self.orig_data - self.buf.strides[0] = self.orig_stride + self.buf = self.orig_data[:] class InvalidApply(Exception): @@ -407,7 +398,7 @@ cdef class BlockSlider: list blocks cdef: - char **base_ptrs + list base_ptrs def __init__(self, object frame): cdef: @@ -430,12 +421,7 @@ cdef class BlockSlider: self.idx_slider = Slider( self.frame.index._index_data, self.dummy.index._index_data) - self.base_ptrs = malloc(sizeof(char*) * len(self.blocks)) - for i, block in enumerate(self.blocks): - self.base_ptrs[i] = (block).data - - def __dealloc__(self): - free(self.base_ptrs) + self.base_ptrs = [block[:] for block in self.blocks] cdef move(self, int start, int end): cdef: @@ -444,11 +430,7 @@ cdef class BlockSlider: # move blocks for i in range(self.nblocks): - arr = self.blocks[i] - - # axis=1 is the frame's axis=0 - arr.data = self.base_ptrs[i] + arr.strides[1] * start - arr.shape[1] = end - start + self.blocks[i] = self.base_ptrs[i][:, start:end] # move and set the index self.idx_slider.move(start, end) @@ -463,8 +445,4 @@ cdef class BlockSlider: # reset blocks for i in range(self.nblocks): - arr = self.blocks[i] - - # axis=1 is the frame's axis=0 - arr.data = self.base_ptrs[i] - arr.shape[1] = 0 + self.blocks[i] = self.base_ptrs[i][:]