Skip to content

REGR: fix rank algo for read-only data #37439

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

Merged
merged 2 commits into from
Oct 27, 2020
Merged
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down