Skip to content

Commit c291463

Browse files
committed
update
1 parent 8c101df commit c291463

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pandas/_libs/index.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,15 @@ cdef class IndexEngine:
230230
def __sizeof__(self) -> int:
231231
return self.sizeof()
232232

233-
cpdef _update_from_other(self, IndexEngine other, reverse: bool):
233+
cpdef _update_from_sliced(self, IndexEngine other, reverse: bool):
234234
self.unique = other.unique
235235
self.need_unique_check = other.need_unique_check
236-
self.need_monotonic_check = other.need_monotonic_check
237-
if reverse and not self.need_monotonic_check:
238-
# the slice reverses the index
239-
self.monotonic_inc = other.monotonic_dec
240-
self.monotonic_dec = other.monotonic_inc
241-
else:
242-
self.monotonic_inc = other.monotonic_inc
243-
self.monotonic_dec = other.monotonic_dec
236+
if not other.need_monotonic_check and (
237+
other.is_monotonic_increasing or other.is_monotonic_decreasing):
238+
self.need_monotonic_check = other.need_monotonic_check
239+
# reverse=True means the index has been reversed
240+
self.monotonic_inc = other.monotonic_dec if reverse else other.monotonic_inc
241+
self.monotonic_dec = other.monotonic_inc if reverse else other.monotonic_dec
244242

245243
@property
246244
def is_unique(self) -> bool:

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5182,7 +5182,7 @@ def _getitem_slice(self: _IndexT, slobj: slice) -> _IndexT:
51825182
result = type(self)._simple_new(res, name=self._name)
51835183
if isinstance(result._engine, libindex.IndexEngine): # may also be IntervalTree
51845184
reverse = slobj.step is not None and slobj.step < 0
5185-
result._engine._update_from_other(self._engine, reverse=reverse)
5185+
result._engine._update_from_sliced(self._engine, reverse=reverse)
51865186

51875187
return result
51885188

0 commit comments

Comments
 (0)