diff --git a/doc/source/whatsnew/v1.1.4.rst b/doc/source/whatsnew/v1.1.4.rst index c0aa1afc34c8f..458d735b42b7f 100644 --- a/doc/source/whatsnew/v1.1.4.rst +++ b/doc/source/whatsnew/v1.1.4.rst @@ -19,6 +19,7 @@ Fixed regressions - 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`). - Fixed regression in :class:`RollingGroupby` with ``sort=False`` not being respected (:issue:`36889`) - Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`) +- Fixed regression in :meth:`Series.rank` method failing for read-only data (:issue:`37290`) - Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`) - Fixed regression in :meth:`DataFrame.resample(...).apply(...)` raised ``AttributeError`` when input was a :class:`DataFrame` and only a :class:`Series` was evaluated (:issue:`36951`) - Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index da5ae97bb067b..f0cf485d9584a 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -325,7 +325,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None): @cython.boundscheck(False) @cython.wraparound(False) -def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1) -> ndarray: +def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarray: cdef: Py_ssize_t i, j, xi, yi, N, K ndarray[float64_t, ndim=2] result @@ -799,7 +799,7 @@ ctypedef fused rank_t: @cython.wraparound(False) @cython.boundscheck(False) def rank_1d( - rank_t[:] in_arr, + ndarray[rank_t, ndim=1] in_arr, ties_method="average", bint ascending=True, na_option="keep", @@ -1018,7 +1018,7 @@ def rank_1d( def rank_2d( - rank_t[:, :] in_arr, + ndarray[rank_t, ndim=2] in_arr, int axis=0, ties_method="average", bint ascending=True, diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index caaca38d07fa5..aefbcee76b5d7 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1691,11 +1691,13 @@ def _check(arr): _check(np.array([np.nan, np.nan, 5.0, 5.0, 5.0, np.nan, 1, 2, 3, np.nan])) _check(np.array([4.0, np.nan, 5.0, 5.0, 5.0, np.nan, 1, 2, 4.0, np.nan])) - def test_basic(self): + def test_basic(self, writable): exp = np.array([1, 2], dtype=np.float64) for dtype in np.typecodes["AllInteger"]: - s = Series([1, 100], dtype=dtype) + data = np.array([1, 100], dtype=dtype) + data.setflags(write=writable) + s = Series(data) tm.assert_numpy_array_equal(algos.rank(s), exp) def test_uint64_overflow(self):