From b507e1be1bb3c74f68773aba089b299c71892c52 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 27 Oct 2022 18:05:52 -0700 Subject: [PATCH 1/6] DEPR: Timestamp.freq --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/_libs/tslibs/nattype.pyx | 2 - pandas/_libs/tslibs/timestamps.pxd | 4 - pandas/_libs/tslibs/timestamps.pyi | 5 +- pandas/_libs/tslibs/timestamps.pyx | 152 ++---------------- pandas/_libs/tslibs/vectorized.pyi | 2 - pandas/_libs/tslibs/vectorized.pyx | 6 +- pandas/core/arrays/datetimelike.py | 1 - pandas/core/arrays/datetimes.py | 7 - pandas/tests/frame/indexing/test_xs.py | 2 +- .../frame/methods/test_first_valid_index.py | 20 --- .../datetimes/methods/test_to_period.py | 8 +- pandas/tests/indexes/datetimes/test_misc.py | 79 +++++---- .../indexes/datetimes/test_scalar_compat.py | 20 +-- pandas/tests/io/test_pickle.py | 2 - pandas/tests/scalar/test_nat.py | 2 +- .../tests/scalar/timestamp/test_arithmetic.py | 34 +--- .../scalar/timestamp/test_constructors.py | 31 +--- .../tests/scalar/timestamp/test_rendering.py | 22 --- .../tests/scalar/timestamp/test_timestamp.py | 99 +++--------- pandas/tests/series/indexing/test_datetime.py | 2 +- pandas/tests/series/indexing/test_getitem.py | 2 +- 22 files changed, 92 insertions(+), 411 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 252c444b2e60c..e937d572f42ea 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -156,6 +156,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Removed deprecated :attr:`Timestamp.freq` (:issue:`14146`) - Removed deprecated :meth:`Categorical.to_dense`, use ``np.asarray(cat)`` instead (:issue:`32639`) - Removed deprecated :meth:`Categorical.take_nd` (:issue:`27745`) - Removed deprecated :meth:`Categorical.mode`, use ``Series(cat).mode()`` instead (:issue:`45033`) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 79299ec38e19c..d82fedc34123e 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -683,8 +683,6 @@ class NaTType(_NaT): ---------- ordinal : int Date corresponding to a proleptic Gregorian ordinal. - freq : str, DateOffset - Offset to apply to the Timestamp. tz : str, pytz.timezone, dateutil.tz.tzfile or None Time zone for the Timestamp. diff --git a/pandas/_libs/tslibs/timestamps.pxd b/pandas/_libs/tslibs/timestamps.pxd index 397df11144d60..fc62e04961dcb 100644 --- a/pandas/_libs/tslibs/timestamps.pxd +++ b/pandas/_libs/tslibs/timestamps.pxd @@ -15,7 +15,6 @@ from pandas._libs.tslibs.offsets cimport BaseOffset cdef _Timestamp create_timestamp_from_ts(int64_t value, npy_datetimestruct dts, tzinfo tz, - BaseOffset freq, bint fold, NPY_DATETIMEUNIT reso=*) @@ -23,7 +22,6 @@ cdef _Timestamp create_timestamp_from_ts(int64_t value, cdef class _Timestamp(ABCTimestamp): cdef readonly: int64_t value, nanosecond, year - BaseOffset _freq NPY_DATETIMEUNIT _creso cdef bint _get_start_end_field(self, str field, freq) @@ -34,7 +32,5 @@ cdef class _Timestamp(ABCTimestamp): cpdef datetime to_pydatetime(_Timestamp self, bint warn=*) cdef bint _compare_outside_nanorange(_Timestamp self, datetime other, int op) except -1 - cpdef void _set_freq(self, freq) - cdef _warn_on_field_deprecation(_Timestamp self, freq, str field) cdef bint _compare_mismatched_resos(_Timestamp self, _Timestamp other, int op) cdef _Timestamp _as_creso(_Timestamp self, NPY_DATETIMEUNIT reso, bint round_ok=*) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index e916d7eb12dbf..cfd94484f512c 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -37,7 +37,6 @@ class Timestamp(datetime): def __new__( # type: ignore[misc] cls: type[_DatetimeT], ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ..., - freq: int | None | str | BaseOffset = ..., tz: str | _tzinfo | None | int = ..., unit: str | int | None = ..., year: int | None = ..., @@ -52,7 +51,6 @@ class Timestamp(datetime): *, fold: int | None = ..., ) -> _DatetimeT | NaTType: ... - def _set_freq(self, freq: BaseOffset | None) -> None: ... @classmethod def _from_value_and_reso( cls, value: int, reso: int, tz: _tzinfo | None @@ -89,7 +87,6 @@ class Timestamp(datetime): def fromordinal( cls: type[_DatetimeT], ordinal: int, - freq: str | BaseOffset | None = ..., tz: _tzinfo | str | None = ..., ) -> _DatetimeT: ... @classmethod @@ -176,7 +173,7 @@ class Timestamp(datetime): def is_year_end(self) -> bool: ... def to_pydatetime(self, warn: bool = ...) -> datetime: ... def to_datetime64(self) -> np.datetime64: ... - def to_period(self, freq: BaseOffset | str | None = ...) -> Period: ... + def to_period(self, freq: BaseOffset | str = ...) -> Period: ... def to_julian_date(self) -> np.float64: ... @property def asm8(self) -> np.datetime64: ... diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 3c3bb8496aa6e..3573631730456 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -97,11 +97,7 @@ from pandas._libs.tslibs.np_datetime import ( OutOfBoundsTimedelta, ) -from pandas._libs.tslibs.offsets cimport ( - BaseOffset, - is_offset_object, - to_offset, -) +from pandas._libs.tslibs.offsets cimport to_offset from pandas._libs.tslibs.timedeltas cimport ( _Timedelta, delta_to_nanoseconds, @@ -134,7 +130,6 @@ cdef inline _Timestamp create_timestamp_from_ts( int64_t value, npy_datetimestruct dts, tzinfo tz, - BaseOffset freq, bint fold, NPY_DATETIMEUNIT reso=NPY_FR_ns, ): @@ -160,7 +155,6 @@ cdef inline _Timestamp create_timestamp_from_ts( dts.sec, dts.us, tz, fold=fold) ts_base.value = value - ts_base._freq = freq ts_base.year = dts.year ts_base.nanosecond = dts.ps // 1000 ts_base._creso = reso @@ -171,7 +165,6 @@ cdef inline _Timestamp create_timestamp_from_ts( def _unpickle_timestamp(value, freq, tz, reso=NPY_FR_ns): # GH#41949 dont warn on unpickle if we have a freq ts = Timestamp._from_value_and_reso(value, reso, tz) - ts._set_freq(freq) return ts @@ -239,21 +232,6 @@ cdef class _Timestamp(ABCTimestamp): max = MinMaxReso("max") resolution = MinMaxReso("resolution") # GH#21336, GH#21365 - cpdef void _set_freq(self, freq): - # set the ._freq attribute without going through the constructor, - # which would issue a warning - # Caller is responsible for validation - self._freq = freq - - @property - def freq(self): - warnings.warn( - "Timestamp.freq is deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self._freq - @property def _unit(self) -> str: """ @@ -284,7 +262,7 @@ cdef class _Timestamp(ABCTimestamp): maybe_localize_tso(obj, tz, reso) return create_timestamp_from_ts( - value, obj.dts, tz=obj.tzinfo, freq=None, fold=obj.fold, reso=reso + value, obj.dts, tz=obj.tzinfo, fold=obj.fold, reso=reso ) @classmethod @@ -454,8 +432,6 @@ cdef class _Timestamp(ABCTimestamp): f"Out of bounds nanosecond timestamp: {new_value}" ) from err - if result is not NaT: - result._set_freq(self._freq) # avoid warning in constructor return result elif is_integer_object(other): @@ -592,7 +568,7 @@ cdef class _Timestamp(ABCTimestamp): if freq: kwds = freq.kwds month_kw = kwds.get('startingMonth', kwds.get('month', 12)) - freqstr = self._freqstr + freqstr = freq.freqstr else: month_kw = 12 freqstr = None @@ -603,31 +579,6 @@ cdef class _Timestamp(ABCTimestamp): field, freqstr, month_kw, self._creso) return out[0] - cdef _warn_on_field_deprecation(self, freq, str field): - """ - Warn if the removal of .freq change the value of start/end properties. - """ - cdef: - bint needs = False - - if freq is not None: - kwds = freq.kwds - month_kw = kwds.get("startingMonth", kwds.get("month", 12)) - freqstr = self._freqstr - if month_kw != 12: - needs = True - if freqstr.startswith("B"): - needs = True - - if needs: - warnings.warn( - "Timestamp.freq is deprecated and will be removed in a future " - "version. When you have a freq, use " - f"freq.{field}(timestamp) instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - @property def is_month_start(self) -> bool: """ @@ -643,11 +594,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_month_start True """ - if self._freq is None: - # fast-path for non-business frequencies - return self.day == 1 - self._warn_on_field_deprecation(self._freq, "is_month_start") - return self._get_start_end_field("is_month_start", self._freq) + return self.day == 1 @property def is_month_end(self) -> bool: @@ -664,11 +611,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_month_end True """ - if self._freq is None: - # fast-path for non-business frequencies - return self.day == self.days_in_month - self._warn_on_field_deprecation(self._freq, "is_month_end") - return self._get_start_end_field("is_month_end", self._freq) + return self.day == self.days_in_month @property def is_quarter_start(self) -> bool: @@ -685,11 +628,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_quarter_start True """ - if self._freq is None: - # fast-path for non-business frequencies - return self.day == 1 and self.month % 3 == 1 - self._warn_on_field_deprecation(self._freq, "is_quarter_start") - return self._get_start_end_field("is_quarter_start", self._freq) + return self.day == 1 and self.month % 3 == 1 @property def is_quarter_end(self) -> bool: @@ -706,11 +645,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_quarter_end True """ - if self._freq is None: - # fast-path for non-business frequencies - return (self.month % 3) == 0 and self.day == self.days_in_month - self._warn_on_field_deprecation(self._freq, "is_quarter_end") - return self._get_start_end_field("is_quarter_end", self._freq) + return (self.month % 3) == 0 and self.day == self.days_in_month @property def is_year_start(self) -> bool: @@ -727,11 +662,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_year_start True """ - if self._freq is None: - # fast-path for non-business frequencies - return self.day == self.month == 1 - self._warn_on_field_deprecation(self._freq, "is_year_start") - return self._get_start_end_field("is_year_start", self._freq) + return self.day == self.month == 1 @property def is_year_end(self) -> bool: @@ -748,11 +679,7 @@ cdef class _Timestamp(ABCTimestamp): >>> ts.is_year_end True """ - if self._freq is None: - # fast-path for non-business frequencies - return self.month == 12 and self.day == 31 - self._warn_on_field_deprecation(self._freq, "is_year_end") - return self._get_start_end_field("is_year_end", self._freq) + return self.month == 12 and self.day == 31 @cython.boundscheck(False) cdef _get_date_name_field(self, str field, object locale): @@ -930,7 +857,6 @@ cdef class _Timestamp(ABCTimestamp): def __setstate__(self, state): self.value = state[0] - self._freq = state[1] self.tzinfo = state[2] if len(state) == 3: @@ -942,7 +868,7 @@ cdef class _Timestamp(ABCTimestamp): self._creso = reso def __reduce__(self): - object_state = self.value, self._freq, self.tzinfo, self._creso + object_state = self.value, None, self.tzinfo, self._creso return (_unpickle_timestamp, object_state) # ----------------------------------------------------------------- @@ -1021,9 +947,8 @@ cdef class _Timestamp(ABCTimestamp): pass tz = f", tz='{zone}'" if zone is not None else "" - freq = "" if self._freq is None else f", freq='{self._freqstr}'" - return f"Timestamp('{stamp}'{tz}{freq})" + return f"Timestamp('{stamp}'{tz})" @property def _repr_base(self) -> str: @@ -1213,15 +1138,6 @@ cdef class _Timestamp(ABCTimestamp): stacklevel=find_stack_level(), ) - if freq is None: - freq = self._freq - warnings.warn( - "In a future version, calling 'Timestamp.to_period()' without " - "passing a 'freq' will raise an exception.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return Period(self, freq=freq) @@ -1244,8 +1160,6 @@ class Timestamp(_Timestamp): ---------- ts_input : datetime-like, str, int, float Value to be converted to Timestamp. - freq : str, DateOffset - Offset which Timestamp will have. tz : str, pytz.timezone, dateutil.tz.tzfile or None Time zone for time which Timestamp will have. unit : str @@ -1303,7 +1217,7 @@ class Timestamp(_Timestamp): """ @classmethod - def fromordinal(cls, ordinal, freq=None, tz=None): + def fromordinal(cls, ordinal, tz=None): """ Construct a timestamp from a a proleptic Gregorian ordinal. @@ -1311,8 +1225,6 @@ class Timestamp(_Timestamp): ---------- ordinal : int Date corresponding to a proleptic Gregorian ordinal. - freq : str, DateOffset - Offset to apply to the Timestamp. tz : str, pytz.timezone, dateutil.tz.tzfile or None Time zone for the Timestamp. @@ -1325,8 +1237,7 @@ class Timestamp(_Timestamp): >>> pd.Timestamp.fromordinal(737425) Timestamp('2020-01-01 00:00:00') """ - return cls(datetime.fromordinal(ordinal), - freq=freq, tz=tz) + return cls(datetime.fromordinal(ordinal), tz=tz) @classmethod def now(cls, tz=None): @@ -1662,20 +1573,7 @@ class Timestamp(_Timestamp): if ts.value == NPY_NAT: return NaT - if freq is None: - # GH 22311: Try to extract the frequency of a given Timestamp input - freq = getattr(ts_input, '_freq', None) - else: - warnings.warn( - "The 'freq' argument in Timestamp is deprecated and will be " - "removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(), - ) - if not is_offset_object(freq): - freq = to_offset(freq) - - return create_timestamp_from_ts(ts.value, ts.dts, ts.tzinfo, freq, ts.fold, ts.creso) + return create_timestamp_from_ts(ts.value, ts.dts, ts.tzinfo, ts.fold, ts.creso) def _round(self, freq, mode, ambiguous='raise', nonexistent='raise'): cdef: @@ -1994,22 +1892,6 @@ timedelta}, default 'raise' "Use tz_localize() or tz_convert() as appropriate" ) - @property - def _freqstr(self): - return getattr(self._freq, "freqstr", self._freq) - - @property - def freqstr(self): - """ - Return the total number of days in the month. - """ - warnings.warn( - "Timestamp.freqstr is deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self._freqstr - def tz_localize(self, tz, ambiguous='raise', nonexistent='raise'): """ Localize the Timestamp to a timezone. @@ -2110,8 +1992,6 @@ default 'raise' ) out = type(self)._from_value_and_reso(value, self._creso, tz=tz) - if out is not NaT: - out._set_freq(self._freq) # avoid warning in constructor return out def tz_convert(self, tz): @@ -2165,8 +2045,6 @@ default 'raise' # Same UTC timestamp, different time zone tz = maybe_get_tz(tz) out = type(self)._from_value_and_reso(self.value, reso=self._creso, tz=tz) - if out is not NaT: - out._set_freq(self._freq) # avoid warning in constructor return out astimezone = tz_convert @@ -2299,7 +2177,7 @@ default 'raise' ts_input, tzobj, nanos=dts.ps // 1000, reso=self._creso ) return create_timestamp_from_ts( - ts.value, dts, tzobj, self._freq, fold, reso=self._creso + ts.value, dts, tzobj, fold, reso=self._creso ) def to_julian_date(self) -> np.float64: diff --git a/pandas/_libs/tslibs/vectorized.pyi b/pandas/_libs/tslibs/vectorized.pyi index d24541aede8d8..22f457b9ddc0b 100644 --- a/pandas/_libs/tslibs/vectorized.pyi +++ b/pandas/_libs/tslibs/vectorized.pyi @@ -7,7 +7,6 @@ from datetime import tzinfo import numpy as np from pandas._libs.tslibs.dtypes import Resolution -from pandas._libs.tslibs.offsets import BaseOffset from pandas._typing import npt def dt64arr_to_periodarr( @@ -34,7 +33,6 @@ def get_resolution( def ints_to_pydatetime( arr: npt.NDArray[np.int64], tz: tzinfo | None = ..., - freq: BaseOffset | None = ..., fold: bool = ..., box: str = ..., reso: int = ..., # NPY_DATETIMEUNIT diff --git a/pandas/_libs/tslibs/vectorized.pyx b/pandas/_libs/tslibs/vectorized.pyx index 6a6b156af3dc4..85f3be8ee73e1 100644 --- a/pandas/_libs/tslibs/vectorized.pyx +++ b/pandas/_libs/tslibs/vectorized.pyx @@ -32,7 +32,6 @@ from .np_datetime cimport ( npy_datetimestruct, pandas_datetime_to_datetimestruct, ) -from .offsets cimport BaseOffset from .period cimport get_period_ordinal from .timestamps cimport create_timestamp_from_ts from .timezones cimport is_utc @@ -95,7 +94,6 @@ def tz_convert_from_utc(ndarray stamps, tzinfo tz, NPY_DATETIMEUNIT reso=NPY_FR_ def ints_to_pydatetime( ndarray stamps, tzinfo tz=None, - BaseOffset freq=None, bint fold=False, str box="datetime", NPY_DATETIMEUNIT reso=NPY_FR_ns, @@ -109,8 +107,6 @@ def ints_to_pydatetime( stamps : array of i8 tz : str, optional convert to this timezone - freq : BaseOffset, optional - freq to convert fold : bint, default is 0 Due to daylight saving time, one wall clock time can occur twice when shifting from summer to winter time; fold describes whether the @@ -183,7 +179,7 @@ def ints_to_pydatetime( if use_ts: res_val = create_timestamp_from_ts( - utc_val, dts, new_tz, freq, fold, reso=reso + utc_val, dts, new_tz, fold, reso=reso ) elif use_pydt: res_val = datetime( diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index bcf4b5d58bf74..9ec32bf268801 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -438,7 +438,6 @@ def astype(self, dtype, copy: bool = True): converted = ints_to_pydatetime( i8data, tz=self.tz, - freq=self.freq, box="timestamp", reso=self._creso, ) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 1768bb7507dd9..a03fb506ad32b 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -520,12 +520,6 @@ def _box_func(self, x: np.datetime64) -> Timestamp | NaTType: # GH#42228 value = x.view("i8") ts = Timestamp._from_value_and_reso(value, reso=self._creso, tz=self.tz) - # Non-overlapping identity check (left operand type: "Timestamp", - # right operand type: "NaTType") - if ts is not NaT: # type: ignore[comparison-overlap] - # GH#41586 - # do this instead of passing to the constructor to avoid FutureWarning - ts._set_freq(self.freq) return ts @property @@ -626,7 +620,6 @@ def __iter__(self) -> Iterator: converted = ints_to_pydatetime( data[start_i:end_i], tz=self.tz, - freq=self.freq, box="timestamp", reso=self._creso, ) diff --git a/pandas/tests/frame/indexing/test_xs.py b/pandas/tests/frame/indexing/test_xs.py index b02870d5d1247..f0df27a160bbc 100644 --- a/pandas/tests/frame/indexing/test_xs.py +++ b/pandas/tests/frame/indexing/test_xs.py @@ -54,7 +54,7 @@ def test_xs(self, float_frame, datetime_frame): assert xs["B"] == "1" with pytest.raises( - KeyError, match=re.escape("Timestamp('1999-12-31 00:00:00', freq='B')") + KeyError, match=re.escape("Timestamp('1999-12-31 00:00:00')") ): datetime_frame.xs(datetime_frame.index[0] - BDay()) diff --git a/pandas/tests/frame/methods/test_first_valid_index.py b/pandas/tests/frame/methods/test_first_valid_index.py index e4cbd892de38e..6009851bab643 100644 --- a/pandas/tests/frame/methods/test_first_valid_index.py +++ b/pandas/tests/frame/methods/test_first_valid_index.py @@ -7,7 +7,6 @@ from pandas import ( DataFrame, Series, - date_range, ) import pandas._testing as tm @@ -73,22 +72,3 @@ def test_first_last_valid_all_nan(self, index_func): ser = frame["foo"] assert ser.first_valid_index() is None assert ser.last_valid_index() is None - - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") - def test_first_last_valid_preserves_freq(self): - # GH#20499: its preserves freq with holes - index = date_range("20110101", periods=30, freq="B") - frame = DataFrame(np.nan, columns=["foo"], index=index) - - frame.iloc[1] = 1 - frame.iloc[-2] = 1 - assert frame.first_valid_index() == frame.index[1] - assert frame.last_valid_index() == frame.index[-2] - assert frame.first_valid_index().freq == frame.index.freq - assert frame.last_valid_index().freq == frame.index.freq - - ts = frame["foo"] - assert ts.first_valid_index() == ts.index[1] - assert ts.last_valid_index() == ts.index[-2] - assert ts.first_valid_index().freq == ts.index.freq - assert ts.last_valid_index().freq == ts.index.freq diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index f6a598bd2a1ed..e8048e63afbf7 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -148,10 +148,9 @@ def test_to_period_tz(self, tz): with tm.assert_produces_warning(UserWarning): # GH#21333 warning that timezone info will be lost # filter warning about freq deprecation - warnings.filterwarnings("ignore", category=FutureWarning) result = ts.to_period()[0] - expected = ts[0].to_period() + expected = ts[0].to_period(ts.freq) assert result == expected @@ -159,7 +158,7 @@ def test_to_period_tz(self, tz): with tm.assert_produces_warning(UserWarning): # GH#21333 warning that timezone info will be lost - result = ts.to_period() + result = ts.to_period(ts.freq) tm.assert_index_equal(result, expected) @@ -168,10 +167,9 @@ def test_to_period_tz_utc_offset_consistency(self, tz): # GH#22905 ts = date_range("1/1/2000", "2/1/2000", tz="Etc/GMT-1") with tm.assert_produces_warning(UserWarning): - warnings.filterwarnings("ignore", category=FutureWarning) result = ts.to_period()[0] - expected = ts[0].to_period() + expected = ts[0].to_period(ts.freq) assert result == expected def test_to_period_nofreq(self): diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index c69c35ee46307..b733cc517bacd 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -18,6 +18,8 @@ import pandas._testing as tm from pandas.core.arrays import DatetimeArray +from pandas.tseries.frequencies import to_offset + class TestDatetime64: def test_no_millisecond_field(self): @@ -142,41 +144,48 @@ def test_datetimeindex_accessors4(self): assert dti.is_month_start[0] == 1 def test_datetimeindex_accessors5(self): - with tm.assert_produces_warning(FutureWarning, match="The 'freq' argument"): - tests = [ - (Timestamp("2013-06-01", freq="M").is_month_start, 1), - (Timestamp("2013-06-01", freq="BM").is_month_start, 0), - (Timestamp("2013-06-03", freq="M").is_month_start, 0), - (Timestamp("2013-06-03", freq="BM").is_month_start, 1), - (Timestamp("2013-02-28", freq="Q-FEB").is_month_end, 1), - (Timestamp("2013-02-28", freq="Q-FEB").is_quarter_end, 1), - (Timestamp("2013-02-28", freq="Q-FEB").is_year_end, 1), - (Timestamp("2013-03-01", freq="Q-FEB").is_month_start, 1), - (Timestamp("2013-03-01", freq="Q-FEB").is_quarter_start, 1), - (Timestamp("2013-03-01", freq="Q-FEB").is_year_start, 1), - (Timestamp("2013-03-31", freq="QS-FEB").is_month_end, 1), - (Timestamp("2013-03-31", freq="QS-FEB").is_quarter_end, 0), - (Timestamp("2013-03-31", freq="QS-FEB").is_year_end, 0), - (Timestamp("2013-02-01", freq="QS-FEB").is_month_start, 1), - (Timestamp("2013-02-01", freq="QS-FEB").is_quarter_start, 1), - (Timestamp("2013-02-01", freq="QS-FEB").is_year_start, 1), - (Timestamp("2013-06-30", freq="BQ").is_month_end, 0), - (Timestamp("2013-06-30", freq="BQ").is_quarter_end, 0), - (Timestamp("2013-06-30", freq="BQ").is_year_end, 0), - (Timestamp("2013-06-28", freq="BQ").is_month_end, 1), - (Timestamp("2013-06-28", freq="BQ").is_quarter_end, 1), - (Timestamp("2013-06-28", freq="BQ").is_year_end, 0), - (Timestamp("2013-06-30", freq="BQS-APR").is_month_end, 0), - (Timestamp("2013-06-30", freq="BQS-APR").is_quarter_end, 0), - (Timestamp("2013-06-30", freq="BQS-APR").is_year_end, 0), - (Timestamp("2013-06-28", freq="BQS-APR").is_month_end, 1), - (Timestamp("2013-06-28", freq="BQS-APR").is_quarter_end, 1), - (Timestamp("2013-03-29", freq="BQS-APR").is_year_end, 1), - (Timestamp("2013-11-01", freq="AS-NOV").is_year_start, 1), - (Timestamp("2013-10-31", freq="AS-NOV").is_year_end, 1), - (Timestamp("2012-02-01").days_in_month, 29), - (Timestamp("2013-02-01").days_in_month, 28), - ] + freq_m = to_offset("M") + bm = to_offset("BM") + qfeb = to_offset("Q-FEB") + qsfeb = to_offset("QS-FEB") + bq = to_offset("BQ") + bqs_apr = to_offset("BQS-APR") + as_nov = to_offset("AS-NOV") + + tests = [ + (freq_m.is_month_start(Timestamp("2013-06-01")), 1), + (bm.is_month_start(Timestamp("2013-06-01")), 0), + (freq_m.is_month_start(Timestamp("2013-06-03")), 0), + (bm.is_month_start(Timestamp("2013-06-03")), 1), + (qfeb.is_month_end(Timestamp("2013-02-28")), 1), + (qfeb.is_quarter_end(Timestamp("2013-02-28")), 1), + (qfeb.is_year_end(Timestamp("2013-02-28")), 1), + (qfeb.is_month_start(Timestamp("2013-03-01")), 1), + (qfeb.is_quarter_start(Timestamp("2013-03-01")), 1), + (qfeb.is_year_start(Timestamp("2013-03-01")), 1), + (qsfeb.is_month_end(Timestamp("2013-03-31")), 1), + (qsfeb.is_quarter_end(Timestamp("2013-03-31")), 0), + (qsfeb.is_year_end(Timestamp("2013-03-31")), 0), + (qsfeb.is_month_start(Timestamp("2013-02-01")), 1), + (qsfeb.is_quarter_start(Timestamp("2013-02-01")), 1), + (qsfeb.is_year_start(Timestamp("2013-02-01")), 1), + (bq.is_month_end(Timestamp("2013-06-30")), 0), + (bq.is_quarter_end(Timestamp("2013-06-30")), 0), + (bq.is_year_end(Timestamp("2013-06-30")), 0), + (bq.is_month_end(Timestamp("2013-06-28")), 1), + (bq.is_quarter_end(Timestamp("2013-06-28")), 1), + (bq.is_year_end(Timestamp("2013-06-28")), 0), + (bqs_apr.is_month_end(Timestamp("2013-06-30")), 0), + (bqs_apr.is_quarter_end(Timestamp("2013-06-30")), 0), + (bqs_apr.is_year_end(Timestamp("2013-06-30")), 0), + (bqs_apr.is_month_end(Timestamp("2013-06-28")), 1), + (bqs_apr.is_quarter_end(Timestamp("2013-06-28")), 1), + (bqs_apr.is_year_end(Timestamp("2013-03-29")), 1), + (as_nov.is_year_start(Timestamp("2013-11-01")), 1), + (as_nov.is_year_end(Timestamp("2013-10-31")), 1), + (Timestamp("2012-02-01").days_in_month, 29), + (Timestamp("2013-02-01").days_in_month, 28), + ] for ts, value in tests: assert ts == value diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index 890590094094a..42aba136f378d 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -64,9 +64,7 @@ def test_dti_timestamp_fields(self, field): idx = tm.makeDateIndex(100) expected = getattr(idx, field)[-1] - warn = FutureWarning if field.startswith("is_") else None - with tm.assert_produces_warning(warn, match="Timestamp.freq is deprecated"): - result = getattr(Timestamp(idx[-1]), field) + result = getattr(Timestamp(idx[-1]), field) assert result == expected def test_dti_timestamp_isocalendar_fields(self): @@ -75,22 +73,6 @@ def test_dti_timestamp_isocalendar_fields(self): result = idx[-1].isocalendar() assert result == expected - def test_dti_timestamp_freq_fields(self): - # extra fields from DatetimeIndex like quarter and week - idx = tm.makeDateIndex(100) - - msg = "The 'freq' argument in Timestamp is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - ts = Timestamp(idx[-1], idx.freq) - - msg2 = "Timestamp.freq is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg2): - assert idx.freq == ts.freq - - msg3 = "Timestamp.freqstr is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg3): - assert idx.freqstr == ts.freqstr - # ---------------------------------------------------------------- # DatetimeIndex.round diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index 5115a33694207..b3cda88015215 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -89,7 +89,6 @@ def compare_element(result, expected, typ): assert result is pd.NaT else: assert result == expected - assert result.freq == expected.freq else: comparator = getattr(tm, f"assert_{typ}_equal", tm.assert_almost_equal) comparator(result, expected) @@ -215,7 +214,6 @@ def python_unpickler(path): ], ) @pytest.mark.parametrize("writer", [pd.to_pickle, python_pickler]) -@pytest.mark.filterwarnings("ignore:The 'freq' argument in Timestamp:FutureWarning") def test_round_trip_current(current_pickle_data, pickle_writer, writer): data = current_pickle_data for typ, dv in data.items(): diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 1fd5f5ab7c2a6..460c58b2f97dc 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -190,7 +190,7 @@ def test_nat_iso_format(get_nat): @pytest.mark.parametrize( "klass,expected", [ - (Timestamp, ["freqstr", "normalize", "to_julian_date", "to_period"]), + (Timestamp, ["normalize", "to_julian_date", "to_period"]), ( Timedelta, [ diff --git a/pandas/tests/scalar/timestamp/test_arithmetic.py b/pandas/tests/scalar/timestamp/test_arithmetic.py index 4283575a67f4c..17fee1ff3f949 100644 --- a/pandas/tests/scalar/timestamp/test_arithmetic.py +++ b/pandas/tests/scalar/timestamp/test_arithmetic.py @@ -158,11 +158,7 @@ def test_addition_subtraction_types(self): # objects dt = datetime(2014, 3, 4) td = timedelta(seconds=1) - # build a timestamp with a frequency, since then it supports - # addition/subtraction of integers - with tm.assert_produces_warning(FutureWarning, match="The 'freq' argument"): - # freq deprecated - ts = Timestamp(dt, freq="D") + ts = Timestamp(dt) msg = "Addition/subtraction of integers" with pytest.raises(TypeError, match=msg): @@ -183,34 +179,6 @@ def test_addition_subtraction_types(self): assert type(ts + td64) == Timestamp assert type(ts - td64) == Timestamp - @pytest.mark.parametrize( - "freq, td, td64", - [ - ("S", timedelta(seconds=1), np.timedelta64(1, "s")), - ("min", timedelta(minutes=1), np.timedelta64(1, "m")), - ("H", timedelta(hours=1), np.timedelta64(1, "h")), - ("D", timedelta(days=1), np.timedelta64(1, "D")), - ("W", timedelta(weeks=1), np.timedelta64(1, "W")), - ("M", None, np.timedelta64(1, "M")), - ], - ) - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") - @pytest.mark.filterwarnings("ignore:The 'freq' argument:FutureWarning") - def test_addition_subtraction_preserve_frequency(self, freq, td, td64): - ts = Timestamp("2014-03-05 00:00:00", freq=freq) - original_freq = ts.freq - - assert (ts + 1 * original_freq).freq == original_freq - assert (ts - 1 * original_freq).freq == original_freq - - if td is not None: - # timedelta does not support months as unit - assert (ts + td).freq == original_freq - assert (ts - td).freq == original_freq - - assert (ts + td64).freq == original_freq - assert (ts - td64).freq == original_freq - @pytest.mark.parametrize( "td", [Timedelta(hours=3), np.timedelta64(3, "h"), timedelta(hours=3)] ) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 341e850a7464e..564b126109fa2 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -22,8 +22,6 @@ ) import pandas._testing as tm -from pandas.tseries import offsets - class TestTimestampConstructors: @pytest.mark.parametrize("typ", [int, float]) @@ -237,15 +235,6 @@ def test_constructor_invalid_tz(self): with pytest.raises(ValueError, match=msg): Timestamp("2017-10-22", tzinfo=pytz.utc, tz="UTC") - msg = "Invalid frequency:" - msg2 = "The 'freq' argument" - with pytest.raises(ValueError, match=msg): - # GH#5168 - # case where user tries to pass tz as an arg, not kwarg, gets - # interpreted as a `freq` - with tm.assert_produces_warning(FutureWarning, match=msg2): - Timestamp("2012-01-01", "US/Pacific") - def test_constructor_strptime(self): # GH25016 # Test support for Timestamp.strptime @@ -348,14 +337,11 @@ def test_constructor_keyword(self): ) ) == repr(Timestamp("2015-11-12 01:02:03.999999")) - @pytest.mark.filterwarnings("ignore:Timestamp.freq is:FutureWarning") - @pytest.mark.filterwarnings("ignore:The 'freq' argument:FutureWarning") def test_constructor_fromordinal(self): base = datetime(2000, 1, 1) - ts = Timestamp.fromordinal(base.toordinal(), freq="D") + ts = Timestamp.fromordinal(base.toordinal()) assert base == ts - assert ts.freq == "D" assert base.toordinal() == ts.toordinal() ts = Timestamp.fromordinal(base.toordinal(), tz="US/Eastern") @@ -609,21 +595,6 @@ def test_construct_with_different_string_format(self, arg): expected = Timestamp(datetime(2013, 1, 1), tz=pytz.FixedOffset(540)) assert result == expected - def test_construct_timestamp_preserve_original_frequency(self): - # GH 22311 - with tm.assert_produces_warning(FutureWarning, match="The 'freq' argument"): - result = Timestamp(Timestamp("2010-08-08", freq="D")).freq - expected = offsets.Day() - assert result == expected - - def test_constructor_invalid_frequency(self): - # GH 22311 - msg = "Invalid frequency:" - msg2 = "The 'freq' argument" - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, match=msg2): - Timestamp("2012-01-01", freq=[]) - @pytest.mark.parametrize("box", [datetime, Timestamp]) def test_raise_tz_and_tzinfo_in_datetime_input(self, box): # GH 23579 diff --git a/pandas/tests/scalar/timestamp/test_rendering.py b/pandas/tests/scalar/timestamp/test_rendering.py index 2f88f96b6bbea..3998142e568fe 100644 --- a/pandas/tests/scalar/timestamp/test_rendering.py +++ b/pandas/tests/scalar/timestamp/test_rendering.py @@ -4,7 +4,6 @@ import pytz # noqa # a test below uses pytz but only inside a `eval` call from pandas import Timestamp -import pandas._testing as tm class TestTimestampRendering: @@ -36,27 +35,6 @@ def test_repr(self, date, freq, tz): assert freq_repr not in repr(date_tz) assert date_tz == eval(repr(date_tz)) - msg = "The 'freq' argument in Timestamp" - with tm.assert_produces_warning(FutureWarning, match=msg): - date_freq = Timestamp(date, freq=freq) - assert date in repr(date_freq) - assert tz_repr not in repr(date_freq) - assert freq_repr in repr(date_freq) - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): - assert date_freq == eval(repr(date_freq)) - - with tm.assert_produces_warning(FutureWarning, match=msg): - date_tz_freq = Timestamp(date, tz=tz, freq=freq) - assert date in repr(date_tz_freq) - assert tz_repr in repr(date_tz_freq) - assert freq_repr in repr(date_tz_freq) - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): - assert date_tz_freq == eval(repr(date_tz_freq)) - def test_repr_utcoffset(self): # This can cause the tz field to be populated, but it's redundant to # include this information in the date-string. diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 4f8c6fcc57186..d8723dd001f75 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -6,7 +6,6 @@ timedelta, ) import locale -import pickle import unicodedata from dateutil.tz import tzutc @@ -36,64 +35,31 @@ import pandas._testing as tm from pandas.tseries import offsets +from pandas.tseries.frequencies import to_offset class TestTimestampProperties: - def test_freq_deprecation(self): - # GH#41586 - msg = "The 'freq' argument in Timestamp is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - # warning issued at construction - ts = Timestamp("2021-06-01", freq="D") - ts2 = Timestamp("2021-06-01", freq="B") - - msg = "Timestamp.freq is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - # warning issued at attribute lookup - ts.freq - - for per in ["month", "quarter", "year"]: - for side in ["start", "end"]: - attr = f"is_{per}_{side}" - - with tm.assert_produces_warning(FutureWarning, match=msg): - getattr(ts2, attr) - - # is_(month|quarter|year)_(start|end) does _not_ issue a warning - # with freq="D" bc the result will be unaffected by the deprecation - with tm.assert_produces_warning(None): - getattr(ts, attr) - - @pytest.mark.filterwarnings("ignore:The 'freq' argument:FutureWarning") - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") def test_properties_business(self): + freq = to_offset("B") + ts = Timestamp("2017-10-01", freq="B") - control = Timestamp("2017-10-01") assert ts.dayofweek == 6 assert ts.day_of_week == 6 - assert not ts.is_month_start # not a weekday - assert not ts.freq.is_month_start(ts) - assert ts.freq.is_month_start(ts + Timedelta(days=1)) - assert not ts.is_quarter_start # not a weekday - assert not ts.freq.is_quarter_start(ts) - assert ts.freq.is_quarter_start(ts + Timedelta(days=1)) - # Control case: non-business is month/qtr start - assert control.is_month_start - assert control.is_quarter_start + assert ts.is_month_start # not a weekday + assert not freq.is_month_start(ts) + assert freq.is_month_start(ts + Timedelta(days=1)) + assert not freq.is_quarter_start(ts) + assert freq.is_quarter_start(ts + Timedelta(days=1)) ts = Timestamp("2017-09-30", freq="B") - control = Timestamp("2017-09-30") assert ts.dayofweek == 5 assert ts.day_of_week == 5 - assert not ts.is_month_end # not a weekday - assert not ts.freq.is_month_end(ts) - assert ts.freq.is_month_end(ts - Timedelta(days=1)) - assert not ts.is_quarter_end # not a weekday - assert not ts.freq.is_quarter_end(ts) - assert ts.freq.is_quarter_end(ts - Timedelta(days=1)) - # Control case: non-business is month/qtr start - assert control.is_month_end - assert control.is_quarter_end + assert ts.is_month_end + assert not freq.is_month_end(ts) + assert freq.is_month_end(ts - Timedelta(days=1)) + assert ts.is_quarter_end + assert not freq.is_quarter_end(ts) + assert freq.is_quarter_end(ts - Timedelta(days=1)) @pytest.mark.parametrize( "attr, expected", @@ -476,26 +442,6 @@ def test_hash_timestamp_with_fold(self, timezone, year, month, day, hour): ) assert hash(transition_1) == hash(transition_2) - def test_tz_conversion_freq(self, tz_naive_fixture): - # GH25241 - with tm.assert_produces_warning(FutureWarning, match="freq"): - t1 = Timestamp("2019-01-01 10:00", freq="H") - assert t1.tz_localize(tz=tz_naive_fixture).freq == t1.freq - with tm.assert_produces_warning(FutureWarning, match="freq"): - t2 = Timestamp("2019-01-02 12:00", tz="UTC", freq="T") - assert t2.tz_convert(tz="UTC").freq == t2.freq - - def test_pickle_freq_no_warning(self): - # GH#41949 we don't want a warning on unpickling - with tm.assert_produces_warning(FutureWarning, match="freq"): - ts = Timestamp("2019-01-01 10:00", freq="H") - - out = pickle.dumps(ts) - with tm.assert_produces_warning(None): - res = pickle.loads(out) - - assert res._freq == ts._freq - class TestTimestampNsOperations: def test_nanosecond_string_parsing(self): @@ -749,18 +695,13 @@ def test_start_end_fields(self, ts): assert not ts.is_month_end assert not ts.is_month_end - freq = offsets.BDay() - ts._set_freq(freq) - # 2016-01-01 is a Friday, so is year/quarter/month start with this freq - msg = "Timestamp.freq is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - assert ts.is_year_start - assert ts.is_quarter_start - assert ts.is_month_start - assert not ts.is_year_end - assert not ts.is_month_end - assert not ts.is_month_end + assert ts.is_year_start + assert ts.is_quarter_start + assert ts.is_month_start + assert not ts.is_year_end + assert not ts.is_month_end + assert not ts.is_month_end def test_day_name(self, dt64, ts): alt = Timestamp(dt64) diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index b8291471225d7..f1d77ad5dbde2 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -479,6 +479,6 @@ def test_getitem_str_second_with_datetimeindex(): with pytest.raises(KeyError, match=r"^'2012-01-02 18:01:02'$"): df["2012-01-02 18:01:02"] - msg = r"Timestamp\('2012-01-02 18:01:02-0600', tz='US/Central', freq='S'\)" + msg = r"Timestamp\('2012-01-02 18:01:02-0600', tz='US/Central'\)" with pytest.raises(KeyError, match=msg): df[df.index[2]] diff --git a/pandas/tests/series/indexing/test_getitem.py b/pandas/tests/series/indexing/test_getitem.py index e3a38fcd10642..12627d31865f6 100644 --- a/pandas/tests/series/indexing/test_getitem.py +++ b/pandas/tests/series/indexing/test_getitem.py @@ -646,7 +646,7 @@ def test_getitem_with_integer_labels(): def test_getitem_missing(datetime_series): # missing d = datetime_series.index[0] - BDay() - msg = r"Timestamp\('1999-12-31 00:00:00', freq='B'\)" + msg = r"Timestamp\('1999-12-31 00:00:00'\)" with pytest.raises(KeyError, match=msg): datetime_series[d] From 6a26d0368a0d0fa3cc7bc7aae978314b64d46dbc Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 28 Oct 2022 07:42:43 -0700 Subject: [PATCH 2/6] __new__, doc --- doc/source/whatsnew/v0.24.0.rst | 2 +- pandas/_libs/tslibs/timestamps.pyx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index f5175283cce4e..fdedff7c47da0 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1357,7 +1357,7 @@ the object's ``freq`` attribute (:issue:`21939`, :issue:`23878`). *New behavior*: .. ipython:: python - :okwarning: + :okexcept: ts = pd.Timestamp('1994-05-06 12:15:16', freq=pd.offsets.Hour()) ts + 2 * ts.freq diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 3573631730456..346e8908f20cc 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1393,7 +1393,6 @@ class Timestamp(_Timestamp): def __new__( cls, object ts_input=_no_input, - object freq=None, tz=None, unit=None, year=None, From 0a161592aa23ba7e7b9c6a6f66bb1f48c83a9731 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 29 Oct 2022 20:43:01 -0700 Subject: [PATCH 3/6] update pickle tests --- pandas/_libs/tslibs/timestamps.pyx | 13 ++++++------- pandas/tests/io/generate_legacy_storage_files.py | 3 --- pandas/tests/io/test_pickle.py | 9 --------- pandas/tests/scalar/timestamp/test_timestamp.py | 4 ++-- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 346e8908f20cc..cae33dbd5168b 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1441,19 +1441,19 @@ class Timestamp(_Timestamp): if tz is not None: if (is_integer_object(tz) and is_integer_object(ts_input) - and is_integer_object(freq) + and is_integer_object(unit) ): # GH#31929 e.g. Timestamp(2019, 3, 4, 5, 6, tzinfo=foo) # TODO(GH#45307): this will still be fragile to # mixed-and-matched positional/keyword arguments ts_input = datetime( ts_input, - freq, tz, unit or 0, year or 0, month or 0, day or 0, + hour or 0, fold=fold or 0, ) nanosecond = hour @@ -1495,7 +1495,7 @@ class Timestamp(_Timestamp): # check that only ts_input is passed # checking verbosely, because cython doesn't optimize # list comprehensions (as of cython 0.29.x) - if (isinstance(ts_input, _Timestamp) and freq is None and + if (isinstance(ts_input, _Timestamp) and tz is None and unit is None and year is None and month is None and day is None and hour is None and minute is None and second is None and @@ -1532,15 +1532,14 @@ class Timestamp(_Timestamp): ts_input = datetime(**datetime_kwargs) - elif is_integer_object(freq): + elif is_integer_object(tz): # User passed positional arguments: # Timestamp(year, month, day[, hour[, minute[, second[, # microsecond[, nanosecond[, tzinfo]]]]]]) - ts_input = datetime(ts_input, freq, tz, unit or 0, - year or 0, month or 0, day or 0, fold=fold or 0) + ts_input = datetime(ts_input, tz, unit or 0, + year or 0, month or 0, day or 0, hour or 0, fold=fold or 0) nanosecond = hour tz = minute - freq = None unit = None if getattr(ts_input, 'tzinfo', None) is not None and tz is not None: diff --git a/pandas/tests/io/generate_legacy_storage_files.py b/pandas/tests/io/generate_legacy_storage_files.py index b66631a7d943e..918cb8ea88018 100644 --- a/pandas/tests/io/generate_legacy_storage_files.py +++ b/pandas/tests/io/generate_legacy_storage_files.py @@ -243,9 +243,6 @@ def create_data(): "tz": Timestamp("2011-01-01", tz="US/Eastern"), } - timestamp["freq"] = Timestamp("2011-01-01", freq="D") - timestamp["both"] = Timestamp("2011-01-01", tz="Asia/Tokyo", freq="M") - off = { "DateOffset": DateOffset(years=1), "DateOffset_h_ns": DateOffset(hour=6, nanoseconds=5824), diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index b3cda88015215..930e547d5cba8 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -26,7 +26,6 @@ import uuid from warnings import ( catch_warnings, - filterwarnings, simplefilter, ) import zipfile @@ -56,10 +55,6 @@ MonthEnd, ) -pytestmark = pytest.mark.filterwarnings( - "ignore:Timestamp.freq is deprecated:FutureWarning" -) - @pytest.fixture(scope="module") def current_pickle_data(): @@ -67,10 +62,6 @@ def current_pickle_data(): from pandas.tests.io.generate_legacy_storage_files import create_pickle_data with catch_warnings(): - filterwarnings( - "ignore", "The 'freq' argument in Timestamp", category=FutureWarning - ) - return create_pickle_data() diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index d8723dd001f75..a9a7a44f54dee 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -42,7 +42,7 @@ class TestTimestampProperties: def test_properties_business(self): freq = to_offset("B") - ts = Timestamp("2017-10-01", freq="B") + ts = Timestamp("2017-10-01") assert ts.dayofweek == 6 assert ts.day_of_week == 6 assert ts.is_month_start # not a weekday @@ -51,7 +51,7 @@ def test_properties_business(self): assert not freq.is_quarter_start(ts) assert freq.is_quarter_start(ts + Timedelta(days=1)) - ts = Timestamp("2017-09-30", freq="B") + ts = Timestamp("2017-09-30") assert ts.dayofweek == 5 assert ts.day_of_week == 5 assert ts.is_month_end From 6c678c5305a214683d6f5d8d863609b5cc8f232a Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 2 Nov 2022 19:41:44 -0700 Subject: [PATCH 4/6] update docs --- doc/redirects.csv | 2 -- doc/source/reference/arrays.rst | 2 -- doc/source/whatsnew/v0.24.0.rst | 1 + pandas/_libs/tslibs/timestamps.pyx | 1 - pandas/tests/frame/methods/test_reset_index.py | 1 - pandas/tests/reshape/concat/test_datetimes.py | 1 - pandas/tests/reshape/test_pivot.py | 1 - 7 files changed, 1 insertion(+), 8 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index d0f4ae331f7e3..dfbaa7cc52d1d 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -1324,8 +1324,6 @@ generated/pandas.Timestamp.daysinmonth,../reference/api/pandas.Timestamp.daysinm generated/pandas.Timestamp.dst,../reference/api/pandas.Timestamp.dst generated/pandas.Timestamp.floor,../reference/api/pandas.Timestamp.floor generated/pandas.Timestamp.fold,../reference/api/pandas.Timestamp.fold -generated/pandas.Timestamp.freq,../reference/api/pandas.Timestamp.freq -generated/pandas.Timestamp.freqstr,../reference/api/pandas.Timestamp.freqstr generated/pandas.Timestamp.fromisoformat,../reference/api/pandas.Timestamp.fromisoformat generated/pandas.Timestamp.fromordinal,../reference/api/pandas.Timestamp.fromordinal generated/pandas.Timestamp.fromtimestamp,../reference/api/pandas.Timestamp.fromtimestamp diff --git a/doc/source/reference/arrays.rst b/doc/source/reference/arrays.rst index 17510a0b7d479..33a611b15675d 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -157,8 +157,6 @@ Methods Timestamp.day_name Timestamp.dst Timestamp.floor - Timestamp.freq - Timestamp.freqstr Timestamp.fromordinal Timestamp.fromtimestamp Timestamp.isocalendar diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index fdedff7c47da0..06356c8b02e84 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1358,6 +1358,7 @@ the object's ``freq`` attribute (:issue:`21939`, :issue:`23878`). .. ipython:: python :okexcept: + :okwarning: ts = pd.Timestamp('1994-05-06 12:15:16', freq=pd.offsets.Hour()) ts + 2 * ts.freq diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 5d658815f32f2..5587e0de4fa54 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1401,7 +1401,6 @@ class Timestamp(_Timestamp): tzinfo_type tzinfo=None, *, nanosecond=None, - object freq=None, tz=None, unit=None, fold=None, diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index 30c033572335a..e03fa317fded9 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -479,7 +479,6 @@ def test_reset_index_allow_duplicates_check(self, multiindex_df, allow_duplicate with pytest.raises(ValueError, match="expected type bool"): multiindex_df.reset_index(allow_duplicates=allow_duplicates) - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") def test_reset_index_datetime(self, tz_naive_fixture): # GH#3950 tz = tz_naive_fixture diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index 1af54a1d5cf4a..93d212d0a581d 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -403,7 +403,6 @@ def test_concat_multiple_tzs(self): expected = DataFrame({"time": [ts2, ts3]}) tm.assert_frame_equal(results, expected) - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") def test_concat_multiindex_with_tz(self): # GH 6606 df = DataFrame( diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index f385453bdb3a1..14ea670fa6cf9 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -525,7 +525,6 @@ def test_pivot_index_with_nan_dates(self, method): result = pd.pivot(df, index="b", columns="a", values="c") tm.assert_frame_equal(result, pv.T) - @pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning") @pytest.mark.parametrize("method", [True, False]) def test_pivot_with_tz(self, method): # GH 5878 From 2bd81c4c1b6a05d16cfe8b95a8cd6ef15b1e7612 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 2 Nov 2022 19:43:14 -0700 Subject: [PATCH 5/6] update asvs --- asv_bench/benchmarks/tslibs/timestamp.py | 44 +++++++++++------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/asv_bench/benchmarks/tslibs/timestamp.py b/asv_bench/benchmarks/tslibs/timestamp.py index eda9bce89188c..d7706a39dfae5 100644 --- a/asv_bench/benchmarks/tslibs/timestamp.py +++ b/asv_bench/benchmarks/tslibs/timestamp.py @@ -50,62 +50,58 @@ def time_from_pd_timestamp(self): class TimestampProperties: - _freqs = [None, "B"] - params = [_tzs, _freqs] - param_names = ["tz", "freq"] + params = [_tzs] + param_names = ["tz"] - def setup(self, tz, freq): - self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz, freq=freq) + def setup(self, tz): + self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz) - def time_tz(self, tz, freq): + def time_tz(self, tz): self.ts.tz - def time_dayofweek(self, tz, freq): + def time_dayofweek(self, tz): self.ts.dayofweek - def time_dayofyear(self, tz, freq): + def time_dayofyear(self, tz): self.ts.dayofyear - def time_week(self, tz, freq): + def time_week(self, tz): self.ts.week - def time_quarter(self, tz, freq): + def time_quarter(self, tz): self.ts.quarter - def time_days_in_month(self, tz, freq): + def time_days_in_month(self, tz): self.ts.days_in_month - def time_freqstr(self, tz, freq): - self.ts.freqstr - - def time_is_month_start(self, tz, freq): + def time_is_month_start(self, tz): self.ts.is_month_start - def time_is_month_end(self, tz, freq): + def time_is_month_end(self, tz): self.ts.is_month_end - def time_is_quarter_start(self, tz, freq): + def time_is_quarter_start(self, tz): self.ts.is_quarter_start - def time_is_quarter_end(self, tz, freq): + def time_is_quarter_end(self, tz): self.ts.is_quarter_end - def time_is_year_start(self, tz, freq): + def time_is_year_start(self, tz): self.ts.is_year_start - def time_is_year_end(self, tz, freq): + def time_is_year_end(self, tz): self.ts.is_year_end - def time_is_leap_year(self, tz, freq): + def time_is_leap_year(self, tz): self.ts.is_leap_year - def time_microsecond(self, tz, freq): + def time_microsecond(self, tz): self.ts.microsecond - def time_month_name(self, tz, freq): + def time_month_name(self, tz): self.ts.month_name() - def time_weekday_name(self, tz, freq): + def time_weekday_name(self, tz): self.ts.day_name() From 0dcf72d7952d6f052d2a44e7bc45361982887d97 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 4 Nov 2022 08:38:26 -0700 Subject: [PATCH 6/6] more whatsnew --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 4af0917e920de..240062bc42d0c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -250,7 +250,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Removed deprecated :attr:`Timestamp.freq` (:issue:`14146`) +- Removed deprecated :attr:`Timestamp.freq`, :attr:`Timestamp.freqstr` and argument ``freq`` from the :class:`Timestamp` constructor and :meth:`Timestamp.fromordinal` (:issue:`14146`) - Removed deprecated :class:`CategoricalBlock`, :meth:`Block.is_categorical`, require datetime64 and timedelta64 values to be wrapped in :class:`DatetimeArray` or :class:`TimedeltaArray` before passing to :meth:`Block.make_block_same_class`, require ``DatetimeTZBlock.values`` to have the correct ndim when passing to the :class:`BlockManager` constructor, and removed the "fastpath" keyword from the :class:`SingleBlockManager` constructor (:issue:`40226`, :issue:`40571`) - Removed deprecated module ``pandas.core.index`` (:issue:`30193`) - Removed deprecated alias ``pandas.core.tools.datetimes.to_time``, import the function directly from ``pandas.core.tools.times`` instead (:issue:`34145`)