Skip to content

Commit a0a6549

Browse files
Backport PR #35707: REGR: fix DataFrame.diff with read-only data (#35721)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent f15a60a commit a0a6549

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

doc/source/whatsnew/v1.1.1.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717

1818
- Fixed regression where :meth:`DataFrame.to_numpy` would raise a ``RuntimeError`` for mixed dtypes when converting to ``str`` (:issue:`35455`)
19-
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`).
19+
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`)
2020
- Fixed regression where :func:`pandas.testing.assert_series_equal` would raise an error when non-numeric dtypes were passed with ``check_exact=True`` (:issue:`35446`)
2121
- Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`)
2222
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
23+
- Fixed regression in :meth:`DataFrame.diff` with read-only data (:issue:`35559`)
2324
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)
2425
- Fixed regression in :meth:`DataFrame.apply` where functions that altered the input in-place only operated on a single row (:issue:`35462`)
2526
- Fixed regression in :meth:`DataFrame.reset_index` would raise a ``ValueError`` on empty :class:`DataFrame` with a :class:`MultiIndex` with a ``datetime64`` dtype level (:issue:`35606`, :issue:`35657`)

pandas/_libs/algos.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,15 @@ ctypedef fused out_t:
12001200
@cython.boundscheck(False)
12011201
@cython.wraparound(False)
12021202
def diff_2d(
1203-
diff_t[:, :] arr,
1204-
out_t[:, :] out,
1203+
ndarray[diff_t, ndim=2] arr, # TODO(cython 3) update to "const diff_t[:, :] arr"
1204+
ndarray[out_t, ndim=2] out,
12051205
Py_ssize_t periods,
12061206
int axis,
12071207
):
12081208
cdef:
12091209
Py_ssize_t i, j, sx, sy, start, stop
1210-
bint f_contig = arr.is_f_contig()
1210+
bint f_contig = arr.flags.f_contiguous
1211+
# bint f_contig = arr.is_f_contig() # TODO(cython 3)
12111212

12121213
# Disable for unsupported dtype combinations,
12131214
# see https://github.com/cython/cython/issues/2646

pandas/tests/frame/methods/test_diff.py

+9
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,12 @@ def test_diff_integer_na(self, axis, expected):
214214
# Test case for default behaviour of diff
215215
result = df.diff(axis=axis)
216216
tm.assert_frame_equal(result, expected)
217+
218+
def test_diff_readonly(self):
219+
# https://github.com/pandas-dev/pandas/issues/35559
220+
arr = np.random.randn(5, 2)
221+
arr.flags.writeable = False
222+
df = pd.DataFrame(arr)
223+
result = df.diff()
224+
expected = pd.DataFrame(np.array(df)).diff()
225+
tm.assert_frame_equal(result, expected)

setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ def run(self):
457457
if sys.version_info[:2] == (3, 8): # GH 33239
458458
extra_compile_args.append("-Wno-error=deprecated-declarations")
459459

460+
# https://github.com/pandas-dev/pandas/issues/35559
461+
extra_compile_args.append("-Wno-error=unreachable-code")
462+
460463
# enable coverage by building cython files by setting the environment variable
461464
# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) or by running build_ext
462465
# with `--with-cython-coverage`enabled

0 commit comments

Comments
 (0)