|
19 | 19 | from pandas._libs import lib |
20 | 20 | from pandas._libs.tslibs import ( |
21 | 21 | BaseOffset, |
22 | | - IncompatibleFrequency, |
23 | 22 | NaT, |
24 | 23 | Period, |
25 | 24 | Timedelta, |
|
79 | 78 | ) |
80 | 79 | from pandas.core.reshape.concat import concat |
81 | 80 |
|
82 | | -from pandas.tseries.frequencies import ( |
83 | | - is_subperiod, |
84 | | - is_superperiod, |
85 | | -) |
86 | 81 | from pandas.tseries.offsets import ( |
87 | 82 | Day, |
88 | 83 | Tick, |
@@ -1938,128 +1933,6 @@ def _resampler_cls(self): |
1938 | 1933 | return DatetimeIndexResampler |
1939 | 1934 |
|
1940 | 1935 |
|
1941 | | -class PeriodIndexResampler(DatetimeIndexResampler): |
1942 | | - # error: Incompatible types in assignment (expression has type "PeriodIndex", base |
1943 | | - # class "DatetimeIndexResampler" defined the type as "DatetimeIndex") |
1944 | | - ax: PeriodIndex # type: ignore[assignment] |
1945 | | - |
1946 | | - @property |
1947 | | - def _resampler_for_grouping(self): |
1948 | | - # TODO: Enforce in 3.0 (#55968) |
1949 | | - warnings.warn( |
1950 | | - "Resampling a groupby with a PeriodIndex is deprecated. " |
1951 | | - "Cast to DatetimeIndex before resampling instead.", |
1952 | | - FutureWarning, # pdlint: ignore[warning_class] |
1953 | | - stacklevel=find_stack_level(), |
1954 | | - ) |
1955 | | - return PeriodIndexResamplerGroupby |
1956 | | - |
1957 | | - def _get_binner_for_time(self): |
1958 | | - if isinstance(self.ax, DatetimeIndex): |
1959 | | - return super()._get_binner_for_time() |
1960 | | - return self._timegrouper._get_period_bins(self.ax) |
1961 | | - |
1962 | | - def _convert_obj(self, obj: NDFrameT) -> NDFrameT: |
1963 | | - obj = super()._convert_obj(obj) |
1964 | | - |
1965 | | - if self._from_selection: |
1966 | | - # see GH 14008, GH 12871 |
1967 | | - msg = ( |
1968 | | - "Resampling from level= or on= selection " |
1969 | | - "with a PeriodIndex is not currently supported, " |
1970 | | - "use .set_index(...) to explicitly set index" |
1971 | | - ) |
1972 | | - raise NotImplementedError(msg) |
1973 | | - |
1974 | | - # convert to timestamp |
1975 | | - if isinstance(obj, DatetimeIndex): |
1976 | | - obj = obj.to_timestamp(how=self.convention) |
1977 | | - |
1978 | | - return obj |
1979 | | - |
1980 | | - def _downsample(self, how, **kwargs): |
1981 | | - """ |
1982 | | - Downsample the cython defined function. |
1983 | | -
|
1984 | | - Parameters |
1985 | | - ---------- |
1986 | | - how : string / cython mapped function |
1987 | | - **kwargs : kw args passed to how function |
1988 | | - """ |
1989 | | - # we may need to actually resample as if we are timestamps |
1990 | | - if isinstance(self.ax, DatetimeIndex): |
1991 | | - return super()._downsample(how, **kwargs) |
1992 | | - |
1993 | | - ax = self.ax |
1994 | | - |
1995 | | - if is_subperiod(ax.freq, self.freq): |
1996 | | - # Downsampling |
1997 | | - return self._groupby_and_aggregate(how, **kwargs) |
1998 | | - elif is_superperiod(ax.freq, self.freq): |
1999 | | - if how == "ohlc": |
2000 | | - # GH #13083 |
2001 | | - # upsampling to subperiods is handled as an asfreq, which works |
2002 | | - # for pure aggregating/reducing methods |
2003 | | - # OHLC reduces along the time dimension, but creates multiple |
2004 | | - # values for each period -> handle by _groupby_and_aggregate() |
2005 | | - return self._groupby_and_aggregate(how) |
2006 | | - return self.asfreq() |
2007 | | - elif ax.freq == self.freq: |
2008 | | - return self.asfreq() |
2009 | | - |
2010 | | - raise IncompatibleFrequency( |
2011 | | - f"Frequency {ax.freq} cannot be resampled to {self.freq}, " |
2012 | | - "as they are not sub or super periods" |
2013 | | - ) |
2014 | | - |
2015 | | - def _upsample(self, method, limit: int | None = None, fill_value=None): |
2016 | | - """ |
2017 | | - Parameters |
2018 | | - ---------- |
2019 | | - method : {'backfill', 'bfill', 'pad', 'ffill'} |
2020 | | - Method for upsampling. |
2021 | | - limit : int, default None |
2022 | | - Maximum size gap to fill when reindexing. |
2023 | | - fill_value : scalar, default None |
2024 | | - Value to use for missing values. |
2025 | | - """ |
2026 | | - # we may need to actually resample as if we are timestamps |
2027 | | - if isinstance(self.ax, DatetimeIndex): |
2028 | | - return super()._upsample(method, limit=limit, fill_value=fill_value) |
2029 | | - |
2030 | | - ax = self.ax |
2031 | | - obj = self.obj |
2032 | | - new_index = self.binner |
2033 | | - |
2034 | | - # Start vs. end of period |
2035 | | - memb = ax.asfreq(self.freq, how=self.convention) |
2036 | | - |
2037 | | - # Get the fill indexer |
2038 | | - if method == "asfreq": |
2039 | | - method = None |
2040 | | - indexer = memb.get_indexer(new_index, method=method, limit=limit) |
2041 | | - new_obj = _take_new_index( |
2042 | | - obj, |
2043 | | - indexer, |
2044 | | - new_index, |
2045 | | - ) |
2046 | | - return self._wrap_result(new_obj) |
2047 | | - |
2048 | | - |
2049 | | -# error: Definition of "ax" in base class "_GroupByMixin" is incompatible with |
2050 | | -# definition in base class "PeriodIndexResampler" |
2051 | | -class PeriodIndexResamplerGroupby( # type: ignore[misc] |
2052 | | - _GroupByMixin, PeriodIndexResampler |
2053 | | -): |
2054 | | - """ |
2055 | | - Provides a resample of a groupby implementation. |
2056 | | - """ |
2057 | | - |
2058 | | - @property |
2059 | | - def _resampler_cls(self): |
2060 | | - return PeriodIndexResampler |
2061 | | - |
2062 | | - |
2063 | 1936 | class TimedeltaIndexResampler(DatetimeIndexResampler): |
2064 | 1937 | # error: Incompatible types in assignment (expression has type "TimedeltaIndex", |
2065 | 1938 | # base class "DatetimeIndexResampler" defined the type as "DatetimeIndex") |
@@ -2292,20 +2165,9 @@ def _get_resampler(self, obj: NDFrame) -> Resampler: |
2292 | 2165 | gpr_index=ax, |
2293 | 2166 | ) |
2294 | 2167 | elif isinstance(ax, PeriodIndex): |
2295 | | - if isinstance(ax, PeriodIndex): |
2296 | | - # TODO: Enforce in 3.0 (#53481) |
2297 | | - # GH#53481 |
2298 | | - warnings.warn( |
2299 | | - "Resampling with a PeriodIndex is deprecated. " |
2300 | | - "Cast index to DatetimeIndex before resampling instead.", |
2301 | | - FutureWarning, # pdlint: ignore[warning_class] |
2302 | | - stacklevel=find_stack_level(), |
2303 | | - ) |
2304 | | - return PeriodIndexResampler( |
2305 | | - obj, |
2306 | | - timegrouper=self, |
2307 | | - group_keys=self.group_keys, |
2308 | | - gpr_index=ax, |
| 2168 | + raise TypeError( |
| 2169 | + "Resampling with a PeriodIndex is not supported. " |
| 2170 | + "Cast index to DatetimeIndex before resampling instead.", |
2309 | 2171 | ) |
2310 | 2172 | elif isinstance(ax, TimedeltaIndex): |
2311 | 2173 | return TimedeltaIndexResampler( |
|
0 commit comments