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