Skip to content

Commit 782ddee

Browse files
jorisvandenbosschemeeseeksmachine
authored andcommitted
Backport PR pandas-dev#37439: REGR: fix rank algo for read-only data
1 parent 9a25cc1 commit 782ddee

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Fixed regressions
1919
- Fixed regression where :meth:`DataFrame.agg` would fail with :exc:`TypeError` when passed positional arguments to be passed on to the aggregation function (:issue:`36948`).
2020
- Fixed regression in :class:`RollingGroupby` with ``sort=False`` not being respected (:issue:`36889`)
2121
- Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`)
22+
- Fixed regression in :meth:`Series.rank` method failing for read-only data (:issue:`37290`)
2223
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
2324
- Fixed regression in :meth:`DataFrame.resample(...).apply(...)` raised ``AttributeError`` when input was a :class:`DataFrame` and only a :class:`Series` was evaluated (:issue:`36951`)
2425
- Fixed regression in ``DataFrame.groupby(..).std()`` with nullable integer dtype (:issue:`37415`)

pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
325325

326326
@cython.boundscheck(False)
327327
@cython.wraparound(False)
328-
def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1) -> ndarray:
328+
def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarray:
329329
cdef:
330330
Py_ssize_t i, j, xi, yi, N, K
331331
ndarray[float64_t, ndim=2] result
@@ -799,7 +799,7 @@ ctypedef fused rank_t:
799799
@cython.wraparound(False)
800800
@cython.boundscheck(False)
801801
def rank_1d(
802-
rank_t[:] in_arr,
802+
ndarray[rank_t, ndim=1] in_arr,
803803
ties_method="average",
804804
bint ascending=True,
805805
na_option="keep",
@@ -1018,7 +1018,7 @@ def rank_1d(
10181018

10191019

10201020
def rank_2d(
1021-
rank_t[:, :] in_arr,
1021+
ndarray[rank_t, ndim=2] in_arr,
10221022
int axis=0,
10231023
ties_method="average",
10241024
bint ascending=True,

pandas/tests/test_algos.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1751,11 +1751,13 @@ def _check(arr):
17511751
_check(np.array([np.nan, np.nan, 5.0, 5.0, 5.0, np.nan, 1, 2, 3, np.nan]))
17521752
_check(np.array([4.0, np.nan, 5.0, 5.0, 5.0, np.nan, 1, 2, 4.0, np.nan]))
17531753

1754-
def test_basic(self):
1754+
def test_basic(self, writable):
17551755
exp = np.array([1, 2], dtype=np.float64)
17561756

17571757
for dtype in np.typecodes["AllInteger"]:
1758-
s = Series([1, 100], dtype=dtype)
1758+
data = np.array([1, 100], dtype=dtype)
1759+
data.setflags(write=writable)
1760+
s = Series(data)
17591761
tm.assert_numpy_array_equal(algos.rank(s), exp)
17601762

17611763
def test_uint64_overflow(self):

0 commit comments

Comments
 (0)