|
27 | 27 | from pandas.core import algorithms |
28 | 28 | from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray |
29 | 29 | from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin |
30 | | -from pandas.core.base import IndexOpsMixin |
31 | 30 | import pandas.core.common as com |
32 | 31 | import pandas.core.indexes.base as ibase |
33 | 32 | from pandas.core.indexes.base import Index, _index_shared_docs |
@@ -217,10 +216,6 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): |
217 | 216 | result._data._freq = freq |
218 | 217 | return result |
219 | 218 |
|
220 | | - @doc(IndexOpsMixin.searchsorted, klass="Datetime-like Index") |
221 | | - def searchsorted(self, value, side="left", sorter=None): |
222 | | - return self._data.searchsorted(value, side=side, sorter=sorter) |
223 | | - |
224 | 219 | _can_hold_na = True |
225 | 220 |
|
226 | 221 | _na_value = NaT |
@@ -256,23 +251,23 @@ def min(self, axis=None, skipna=True, *args, **kwargs): |
256 | 251 | return self._na_value |
257 | 252 |
|
258 | 253 | i8 = self.asi8 |
259 | | - try: |
| 254 | + |
| 255 | + if len(i8) and self.is_monotonic_increasing: |
260 | 256 | # quick check |
261 | | - if len(i8) and self.is_monotonic: |
262 | | - if i8[0] != iNaT: |
263 | | - return self._data._box_func(i8[0]) |
264 | | - |
265 | | - if self.hasnans: |
266 | | - if skipna: |
267 | | - min_stamp = self[~self._isnan].asi8.min() |
268 | | - else: |
269 | | - return self._na_value |
270 | | - else: |
271 | | - min_stamp = i8.min() |
272 | | - return self._data._box_func(min_stamp) |
273 | | - except ValueError: |
| 257 | + if i8[0] != iNaT: |
| 258 | + return self._data._box_func(i8[0]) |
| 259 | + |
| 260 | + if self.hasnans: |
| 261 | + if not skipna: |
| 262 | + return self._na_value |
| 263 | + i8 = i8[~self._isnan] |
| 264 | + |
| 265 | + if not len(i8): |
274 | 266 | return self._na_value |
275 | 267 |
|
| 268 | + min_stamp = i8.min() |
| 269 | + return self._data._box_func(min_stamp) |
| 270 | + |
276 | 271 | def argmin(self, axis=None, skipna=True, *args, **kwargs): |
277 | 272 | """ |
278 | 273 | Returns the indices of the minimum values along an axis. |
@@ -313,23 +308,23 @@ def max(self, axis=None, skipna=True, *args, **kwargs): |
313 | 308 | return self._na_value |
314 | 309 |
|
315 | 310 | i8 = self.asi8 |
316 | | - try: |
| 311 | + |
| 312 | + if len(i8) and self.is_monotonic: |
317 | 313 | # quick check |
318 | | - if len(i8) and self.is_monotonic: |
319 | | - if i8[-1] != iNaT: |
320 | | - return self._data._box_func(i8[-1]) |
321 | | - |
322 | | - if self.hasnans: |
323 | | - if skipna: |
324 | | - max_stamp = self[~self._isnan].asi8.max() |
325 | | - else: |
326 | | - return self._na_value |
327 | | - else: |
328 | | - max_stamp = i8.max() |
329 | | - return self._data._box_func(max_stamp) |
330 | | - except ValueError: |
| 314 | + if i8[-1] != iNaT: |
| 315 | + return self._data._box_func(i8[-1]) |
| 316 | + |
| 317 | + if self.hasnans: |
| 318 | + if not skipna: |
| 319 | + return self._na_value |
| 320 | + i8 = i8[~self._isnan] |
| 321 | + |
| 322 | + if not len(i8): |
331 | 323 | return self._na_value |
332 | 324 |
|
| 325 | + max_stamp = i8.max() |
| 326 | + return self._data._box_func(max_stamp) |
| 327 | + |
333 | 328 | def argmax(self, axis=None, skipna=True, *args, **kwargs): |
334 | 329 | """ |
335 | 330 | Returns the indices of the maximum values along an axis. |
@@ -463,7 +458,7 @@ def _partial_date_slice( |
463 | 458 | vals = self._data._ndarray |
464 | 459 | unbox = self._data._unbox |
465 | 460 |
|
466 | | - if self.is_monotonic: |
| 461 | + if self.is_monotonic_increasing: |
467 | 462 |
|
468 | 463 | if len(self) and ( |
469 | 464 | (t1 < self[0] and t2 < self[0]) or (t1 > self[-1] and t2 > self[-1]) |
|
0 commit comments