|
36 | 36 | from pandas._libs.lib import is_range_indexer
|
37 | 37 | from pandas._libs.tslibs import (
|
38 | 38 | Period,
|
39 |
| - Tick, |
40 | 39 | Timestamp,
|
41 | 40 | to_offset,
|
42 | 41 | )
|
@@ -9646,169 +9645,6 @@ def resample(
|
9646 | 9645 | group_keys=group_keys,
|
9647 | 9646 | )
|
9648 | 9647 |
|
9649 |
| - @final |
9650 |
| - def first(self, offset) -> Self: |
9651 |
| - """ |
9652 |
| - Select initial periods of time series data based on a date offset. |
9653 |
| -
|
9654 |
| - .. deprecated:: 2.1 |
9655 |
| - :meth:`.first` is deprecated and will be removed in a future version. |
9656 |
| - Please create a mask and filter using `.loc` instead. |
9657 |
| -
|
9658 |
| - For a DataFrame with a sorted DatetimeIndex, this function can |
9659 |
| - select the first few rows based on a date offset. |
9660 |
| -
|
9661 |
| - Parameters |
9662 |
| - ---------- |
9663 |
| - offset : str, DateOffset or dateutil.relativedelta |
9664 |
| - The offset length of the data that will be selected. For instance, |
9665 |
| - '1ME' will display all the rows having their index within the first month. |
9666 |
| -
|
9667 |
| - Returns |
9668 |
| - ------- |
9669 |
| - Series or DataFrame |
9670 |
| - A subset of the caller. |
9671 |
| -
|
9672 |
| - Raises |
9673 |
| - ------ |
9674 |
| - TypeError |
9675 |
| - If the index is not a :class:`DatetimeIndex` |
9676 |
| -
|
9677 |
| - See Also |
9678 |
| - -------- |
9679 |
| - last : Select final periods of time series based on a date offset. |
9680 |
| - at_time : Select values at a particular time of the day. |
9681 |
| - between_time : Select values between particular times of the day. |
9682 |
| -
|
9683 |
| - Examples |
9684 |
| - -------- |
9685 |
| - >>> i = pd.date_range('2018-04-09', periods=4, freq='2D') |
9686 |
| - >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i) |
9687 |
| - >>> ts |
9688 |
| - A |
9689 |
| - 2018-04-09 1 |
9690 |
| - 2018-04-11 2 |
9691 |
| - 2018-04-13 3 |
9692 |
| - 2018-04-15 4 |
9693 |
| -
|
9694 |
| - Get the rows for the first 3 days: |
9695 |
| -
|
9696 |
| - >>> ts.first('3D') |
9697 |
| - A |
9698 |
| - 2018-04-09 1 |
9699 |
| - 2018-04-11 2 |
9700 |
| -
|
9701 |
| - Notice the data for 3 first calendar days were returned, not the first |
9702 |
| - 3 days observed in the dataset, and therefore data for 2018-04-13 was |
9703 |
| - not returned. |
9704 |
| - """ |
9705 |
| - warnings.warn( |
9706 |
| - "first is deprecated and will be removed in a future version. " |
9707 |
| - "Please create a mask and filter using `.loc` instead", |
9708 |
| - FutureWarning, |
9709 |
| - stacklevel=find_stack_level(), |
9710 |
| - ) |
9711 |
| - if not isinstance(self.index, DatetimeIndex): |
9712 |
| - raise TypeError("'first' only supports a DatetimeIndex index") |
9713 |
| - |
9714 |
| - if len(self.index) == 0: |
9715 |
| - return self.copy(deep=False) |
9716 |
| - |
9717 |
| - offset = to_offset(offset) |
9718 |
| - if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]): |
9719 |
| - # GH#29623 if first value is end of period, remove offset with n = 1 |
9720 |
| - # before adding the real offset |
9721 |
| - end_date = end = self.index[0] - offset.base + offset |
9722 |
| - else: |
9723 |
| - end_date = end = self.index[0] + offset |
9724 |
| - |
9725 |
| - # Tick-like, e.g. 3 weeks |
9726 |
| - if isinstance(offset, Tick) and end_date in self.index: |
9727 |
| - end = self.index.searchsorted(end_date, side="left") |
9728 |
| - return self.iloc[:end] |
9729 |
| - |
9730 |
| - return self.loc[:end] |
9731 |
| - |
9732 |
| - @final |
9733 |
| - def last(self, offset) -> Self: |
9734 |
| - """ |
9735 |
| - Select final periods of time series data based on a date offset. |
9736 |
| -
|
9737 |
| - .. deprecated:: 2.1 |
9738 |
| - :meth:`.last` is deprecated and will be removed in a future version. |
9739 |
| - Please create a mask and filter using `.loc` instead. |
9740 |
| -
|
9741 |
| - For a DataFrame with a sorted DatetimeIndex, this function |
9742 |
| - selects the last few rows based on a date offset. |
9743 |
| -
|
9744 |
| - Parameters |
9745 |
| - ---------- |
9746 |
| - offset : str, DateOffset, dateutil.relativedelta |
9747 |
| - The offset length of the data that will be selected. For instance, |
9748 |
| - '3D' will display all the rows having their index within the last 3 days. |
9749 |
| -
|
9750 |
| - Returns |
9751 |
| - ------- |
9752 |
| - Series or DataFrame |
9753 |
| - A subset of the caller. |
9754 |
| -
|
9755 |
| - Raises |
9756 |
| - ------ |
9757 |
| - TypeError |
9758 |
| - If the index is not a :class:`DatetimeIndex` |
9759 |
| -
|
9760 |
| - See Also |
9761 |
| - -------- |
9762 |
| - first : Select initial periods of time series based on a date offset. |
9763 |
| - at_time : Select values at a particular time of the day. |
9764 |
| - between_time : Select values between particular times of the day. |
9765 |
| -
|
9766 |
| - Notes |
9767 |
| - ----- |
9768 |
| - .. deprecated:: 2.1.0 |
9769 |
| - Please create a mask and filter using `.loc` instead |
9770 |
| -
|
9771 |
| - Examples |
9772 |
| - -------- |
9773 |
| - >>> i = pd.date_range('2018-04-09', periods=4, freq='2D') |
9774 |
| - >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i) |
9775 |
| - >>> ts |
9776 |
| - A |
9777 |
| - 2018-04-09 1 |
9778 |
| - 2018-04-11 2 |
9779 |
| - 2018-04-13 3 |
9780 |
| - 2018-04-15 4 |
9781 |
| -
|
9782 |
| - Get the rows for the last 3 days: |
9783 |
| -
|
9784 |
| - >>> ts.last('3D') # doctest: +SKIP |
9785 |
| - A |
9786 |
| - 2018-04-13 3 |
9787 |
| - 2018-04-15 4 |
9788 |
| -
|
9789 |
| - Notice the data for 3 last calendar days were returned, not the last |
9790 |
| - 3 observed days in the dataset, and therefore data for 2018-04-11 was |
9791 |
| - not returned. |
9792 |
| - """ |
9793 |
| - warnings.warn( |
9794 |
| - "last is deprecated and will be removed in a future version. " |
9795 |
| - "Please create a mask and filter using `.loc` instead", |
9796 |
| - FutureWarning, |
9797 |
| - stacklevel=find_stack_level(), |
9798 |
| - ) |
9799 |
| - |
9800 |
| - if not isinstance(self.index, DatetimeIndex): |
9801 |
| - raise TypeError("'last' only supports a DatetimeIndex index") |
9802 |
| - |
9803 |
| - if len(self.index) == 0: |
9804 |
| - return self.copy(deep=False) |
9805 |
| - |
9806 |
| - offset = to_offset(offset) |
9807 |
| - |
9808 |
| - start_date = self.index[-1] - offset |
9809 |
| - start = self.index.searchsorted(start_date, side="right") |
9810 |
| - return self.iloc[start:] |
9811 |
| - |
9812 | 9648 | @final
|
9813 | 9649 | def rank(
|
9814 | 9650 | self,
|
|
0 commit comments