|
19 | 19 |
|
20 | 20 | import numpy as np
|
21 | 21 |
|
| 22 | +from pandas.core.algorithms import take |
22 | 23 | from pandas._config.config import get_option
|
23 | 24 |
|
24 | 25 | from pandas._libs import (
|
|
67 | 68 | SequenceIndexer,
|
68 | 69 | TimeAmbiguous,
|
69 | 70 | TimeNonexistent,
|
| 71 | + TakeIndexer, |
70 | 72 | npt,
|
71 | 73 | )
|
72 | 74 | from pandas.compat.numpy import function as nv
|
@@ -1768,7 +1770,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1768 | 1770 | ----------
|
1769 | 1771 | freq : str or Offset
|
1770 | 1772 | The frequency level to {op} the index to. Must be a fixed
|
1771 |
| - frequency like 's' (second) not 'ME' (month end). See |
| 1773 | + frequency like 'S' (second) not 'ME' (month end). See |
1772 | 1774 | :ref:`frequency aliases <timeseries.offset_aliases>` for
|
1773 | 1775 | a list of possible `freq` values.
|
1774 | 1776 | ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
|
@@ -1806,11 +1808,6 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
|
1806 | 1808 | ------
|
1807 | 1809 | ValueError if the `freq` cannot be converted.
|
1808 | 1810 |
|
1809 |
| - See Also |
1810 |
| - -------- |
1811 |
| - DatetimeIndex.floor : Perform floor operation on the data to the specified `freq`. |
1812 |
| - DatetimeIndex.snap : Snap time stamps to nearest occurring frequency. |
1813 |
| -
|
1814 | 1811 | Notes
|
1815 | 1812 | -----
|
1816 | 1813 | If the timestamps have a timezone, {op}ing will take place relative to the
|
@@ -2339,6 +2336,35 @@ def interpolate(
|
2339 | 2336 | if not copy:
|
2340 | 2337 | return self
|
2341 | 2338 | return type(self)._simple_new(out_data, dtype=self.dtype)
|
| 2339 | + |
| 2340 | + def take( |
| 2341 | + self, |
| 2342 | + indices: TakeIndexer, |
| 2343 | + *, |
| 2344 | + allow_fill: bool = False, |
| 2345 | + fill_value: Any = None, |
| 2346 | + axis: AxisInt = 0, |
| 2347 | + ) -> Self: |
| 2348 | + |
| 2349 | + if allow_fill: |
| 2350 | + fill_value = self._validate_scalar(fill_value) |
| 2351 | + |
| 2352 | + new_data = take( |
| 2353 | + self._ndarray, |
| 2354 | + indices, |
| 2355 | + allow_fill=allow_fill, |
| 2356 | + fill_value=fill_value, |
| 2357 | + axis=axis, |
| 2358 | + ) |
| 2359 | + result = self._from_backing_data(new_data) |
| 2360 | + indices = np.asarray(indices, dtype=np.intp) |
| 2361 | + maybe_slice = lib.maybe_indices_to_slice(indices, len(self)) |
| 2362 | + |
| 2363 | + if isinstance(maybe_slice, slice): |
| 2364 | + freq = self._get_getitem_freq(maybe_slice) |
| 2365 | + result.freq = freq |
| 2366 | + |
| 2367 | + return result |
2342 | 2368 |
|
2343 | 2369 | # --------------------------------------------------------------
|
2344 | 2370 | # Unsorted
|
|
0 commit comments