|
20 | 20 |
|
21 | 21 | import numpy as np
|
22 | 22 |
|
| 23 | +from pandas.core.algorithms import take |
23 | 24 | from pandas._config.config import get_option
|
24 | 25 |
|
25 | 26 | from pandas._libs import (
|
|
68 | 69 | SequenceIndexer,
|
69 | 70 | TimeAmbiguous,
|
70 | 71 | TimeNonexistent,
|
| 72 | + TakeIndexer, |
71 | 73 | npt,
|
72 | 74 | )
|
73 | 75 | from pandas.compat.numpy import function as nv
|
@@ -1797,7 +1799,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1797 | 1799 | ----------
|
1798 | 1800 | freq : str or Offset
|
1799 | 1801 | The frequency level to {op} the index to. Must be a fixed
|
1800 |
| - frequency like 's' (second) not 'ME' (month end). See |
| 1802 | + frequency like 'S' (second) not 'ME' (month end). See |
1801 | 1803 | :ref:`frequency aliases <timeseries.offset_aliases>` for
|
1802 | 1804 | a list of possible `freq` values.
|
1803 | 1805 | ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
|
@@ -1835,11 +1837,6 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1835 | 1837 | ------
|
1836 | 1838 | ValueError if the `freq` cannot be converted.
|
1837 | 1839 |
|
1838 |
| - See Also |
1839 |
| - -------- |
1840 |
| - DatetimeIndex.floor : Perform floor operation on the data to the specified `freq`. |
1841 |
| - DatetimeIndex.snap : Snap time stamps to nearest occurring frequency. |
1842 |
| -
|
1843 | 1840 | Notes
|
1844 | 1841 | -----
|
1845 | 1842 | If the timestamps have a timezone, {op}ing will take place relative to the
|
@@ -2368,6 +2365,35 @@ def interpolate(
|
2368 | 2365 | if not copy:
|
2369 | 2366 | return self
|
2370 | 2367 | return type(self)._simple_new(out_data, dtype=self.dtype)
|
| 2368 | + |
| 2369 | + def take( |
| 2370 | + self, |
| 2371 | + indices: TakeIndexer, |
| 2372 | + *, |
| 2373 | + allow_fill: bool = False, |
| 2374 | + fill_value: Any = None, |
| 2375 | + axis: AxisInt = 0, |
| 2376 | + ) -> Self: |
| 2377 | + |
| 2378 | + if allow_fill: |
| 2379 | + fill_value = self._validate_scalar(fill_value) |
| 2380 | + |
| 2381 | + new_data = take( |
| 2382 | + self._ndarray, |
| 2383 | + indices, |
| 2384 | + allow_fill=allow_fill, |
| 2385 | + fill_value=fill_value, |
| 2386 | + axis=axis, |
| 2387 | + ) |
| 2388 | + result = self._from_backing_data(new_data) |
| 2389 | + indices = np.asarray(indices, dtype=np.intp) |
| 2390 | + maybe_slice = lib.maybe_indices_to_slice(indices, len(self)) |
| 2391 | + |
| 2392 | + if isinstance(maybe_slice, slice): |
| 2393 | + freq = self._get_getitem_freq(maybe_slice) |
| 2394 | + result.freq = freq |
| 2395 | + |
| 2396 | + return result |
2371 | 2397 |
|
2372 | 2398 | # --------------------------------------------------------------
|
2373 | 2399 | # Unsorted
|
|
0 commit comments