Skip to content

Commit ca5d28c

Browse files
Fixed whatsnew; copy value in rank_1d
1 parent 9c07153 commit ca5d28c

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

doc/source/whatsnew/v0.22.0.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,5 @@ Categorical
335335
Other
336336
^^^^^
337337

338-
- Improved error message when attempting to use a Python keyword as an identifier in a numexpr query (:issue:`18221`)
339-
- Fixed a bug where creating a Series from an array that contains both tz-naive and tz-aware values will result in a Series whose dtype is tz-aware instead of object (:issue:`16406`)
340-
- Adding a ``Period`` object to a ``datetime`` or ``Timestamp`` object will now correctly raise a ``TypeError`` (:issue:`17983`)
338+
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`)
341339
- Bug in :func:`Series.rank` where ``Series`` containing ``NaT`` modifies the ``Series`` inplace (:issue:`18521`)

pandas/_libs/algos_rank_helper.pxi.in

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average', ascending=True,
8484
mask = np.isnan(values)
8585
{{elif dtype == 'int64'}}
8686
mask = values == iNaT
87+
# create copy in case of iNaT
88+
if mask.any():
89+
values = values.copy()
8790
{{endif}}
8891

8992
# double sort first by mask and then by values to ensure nan values are

pandas/core/algorithms.py

-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ def _get_data_algo(values, func_map):
219219
if is_categorical_dtype(values):
220220
values = values._values_for_rank()
221221

222-
# Create copy in case NaT converts to asi8
223-
if is_datetime64_any_dtype(values):
224-
values = values.copy()
225-
226222
values, dtype, ndtype = _ensure_data(values)
227223
if ndtype == 'object':
228224

0 commit comments

Comments
 (0)