|
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
|
@@ -1787,7 +1789,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1787 | 1789 | ----------
|
1788 | 1790 | freq : str or Offset
|
1789 | 1791 | The frequency level to {op} the index to. Must be a fixed
|
1790 |
| - frequency like 's' (second) not 'ME' (month end). See |
| 1792 | + frequency like 'S' (second) not 'ME' (month end). See |
1791 | 1793 | :ref:`frequency aliases <timeseries.offset_aliases>` for
|
1792 | 1794 | a list of possible `freq` values.
|
1793 | 1795 | ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
|
@@ -1825,11 +1827,6 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1825 | 1827 | ------
|
1826 | 1828 | ValueError if the `freq` cannot be converted.
|
1827 | 1829 |
|
1828 |
| - See Also |
1829 |
| - -------- |
1830 |
| - DatetimeIndex.floor : Perform floor operation on the data to the specified `freq`. |
1831 |
| - DatetimeIndex.snap : Snap time stamps to nearest occurring frequency. |
1832 |
| -
|
1833 | 1830 | Notes
|
1834 | 1831 | -----
|
1835 | 1832 | If the timestamps have a timezone, {op}ing will take place relative to the
|
@@ -2358,6 +2355,35 @@ def interpolate(
|
2358 | 2355 | if not copy:
|
2359 | 2356 | return self
|
2360 | 2357 | return type(self)._simple_new(out_data, dtype=self.dtype)
|
| 2358 | + |
| 2359 | + def take( |
| 2360 | + self, |
| 2361 | + indices: TakeIndexer, |
| 2362 | + *, |
| 2363 | + allow_fill: bool = False, |
| 2364 | + fill_value: Any = None, |
| 2365 | + axis: AxisInt = 0, |
| 2366 | + ) -> Self: |
| 2367 | + |
| 2368 | + if allow_fill: |
| 2369 | + fill_value = self._validate_scalar(fill_value) |
| 2370 | + |
| 2371 | + new_data = take( |
| 2372 | + self._ndarray, |
| 2373 | + indices, |
| 2374 | + allow_fill=allow_fill, |
| 2375 | + fill_value=fill_value, |
| 2376 | + axis=axis, |
| 2377 | + ) |
| 2378 | + result = self._from_backing_data(new_data) |
| 2379 | + indices = np.asarray(indices, dtype=np.intp) |
| 2380 | + maybe_slice = lib.maybe_indices_to_slice(indices, len(self)) |
| 2381 | + |
| 2382 | + if isinstance(maybe_slice, slice): |
| 2383 | + freq = self._get_getitem_freq(maybe_slice) |
| 2384 | + result.freq = freq |
| 2385 | + |
| 2386 | + return result |
2361 | 2387 |
|
2362 | 2388 | # --------------------------------------------------------------
|
2363 | 2389 | # Unsorted
|
|
0 commit comments