From 287fdefa259d16e14787915d3b399ee52c9c7f82 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 22 Dec 2023 16:53:19 +0100 Subject: [PATCH 1/6] deprecate is_anchored, fix tests --- pandas/_libs/tslibs/offsets.pyx | 32 +++++++++++++++++++ .../indexes/interval/test_interval_range.py | 2 +- pandas/tests/tseries/offsets/test_ticks.py | 6 +++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index b3788b6003e67..e73bc8173f824 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -768,6 +768,12 @@ cdef class BaseOffset: >>> pd.DateOffset(2).is_anchored() False """ + warnings.warn( + f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"in a future version, please use {type(self).__name__}.n == 1 instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.n == 1 # ------------------------------------------------------------------ @@ -954,6 +960,12 @@ cdef class Tick(SingleConstructorOffset): return True def is_anchored(self) -> bool: + warnings.warn( + f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"in a future version, please use False instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return False # This is identical to BaseOffset.__hash__, but has to be redefined here @@ -2663,6 +2675,13 @@ cdef class QuarterOffset(SingleConstructorOffset): return f"{self._prefix}-{month}" def is_anchored(self) -> bool: + warnings.warn( + f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"in a future version, please use {type(self).__name__}.n == 1 " + f" and {type(self).__name__}.startingMonth is not None instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.n == 1 and self.startingMonth is not None def is_on_offset(self, dt: datetime) -> bool: @@ -3308,6 +3327,13 @@ cdef class Week(SingleConstructorOffset): self._cache = state.pop("_cache", {}) def is_anchored(self) -> bool: + warnings.warn( + f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"in a future version, please use {type(self).__name__}.n == 1 " + f" and {type(self).__name__}.weekday is not None instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.n == 1 and self.weekday is not None @apply_wraps @@ -3597,6 +3623,12 @@ cdef class FY5253Mixin(SingleConstructorOffset): self.variation = state.pop("variation") def is_anchored(self) -> bool: + warnings.warn( + f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"in a future version, please use {type(self).__name__}.n == 1 instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return ( self.n == 1 and self.startingMonth is not None and self.weekday is not None ) diff --git a/pandas/tests/indexes/interval/test_interval_range.py b/pandas/tests/indexes/interval/test_interval_range.py index d4d4a09c44d13..eaa84b1babdc5 100644 --- a/pandas/tests/indexes/interval/test_interval_range.py +++ b/pandas/tests/indexes/interval/test_interval_range.py @@ -84,7 +84,7 @@ def test_constructor_timestamp(self, closed, name, freq, periods, tz): tm.assert_index_equal(result, expected) # GH 20976: linspace behavior defined from start/end/periods - if not breaks.freq.is_anchored() and tz is None: + if not breaks.freq.n == 1 and tz is None: # matches expected only for non-anchored offsets and tz naive # (anchored/DST transitions cause unequal spacing in expected) result = interval_range( diff --git a/pandas/tests/tseries/offsets/test_ticks.py b/pandas/tests/tseries/offsets/test_ticks.py index b68b91826bc6f..d357573d7ed4e 100644 --- a/pandas/tests/tseries/offsets/test_ticks.py +++ b/pandas/tests/tseries/offsets/test_ticks.py @@ -339,7 +339,11 @@ def test_tick_equalities(cls): @pytest.mark.parametrize("cls", tick_classes) def test_tick_offset(cls): - assert not cls().is_anchored() + msg = f"{cls.__name__}.is_anchored() is deprecated and will be removed in a " + "future version, please use False instead." + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert not cls().is_anchored() @pytest.mark.parametrize("cls", tick_classes) From 8c870f6010f5fa5a6581bf29060dffc879474e3c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 28 Dec 2023 10:55:12 +0100 Subject: [PATCH 2/6] fix tests --- pandas/tests/tseries/offsets/test_offsets.py | 8 ++++++-- pandas/tests/tseries/offsets/test_ticks.py | 3 +-- pandas/tests/tseries/offsets/test_week.py | 12 ++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index ddf56e68b1611..30eb952b11e5c 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -625,8 +625,12 @@ def test_default_constructor(self, dt): assert (dt + DateOffset(2)) == datetime(2008, 1, 4) def test_is_anchored(self): - assert not DateOffset(2).is_anchored() - assert DateOffset(1).is_anchored() + msg = "DateOffset.is_anchored() is deprecated and will be removed " + "in a future version, please use DateOffset.n == 1 instead." + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert not DateOffset(2).is_anchored() + assert DateOffset(1).is_anchored() def test_copy(self): assert DateOffset(months=2).copy() == DateOffset(months=2) diff --git a/pandas/tests/tseries/offsets/test_ticks.py b/pandas/tests/tseries/offsets/test_ticks.py index d357573d7ed4e..462ca112b3faf 100644 --- a/pandas/tests/tseries/offsets/test_ticks.py +++ b/pandas/tests/tseries/offsets/test_ticks.py @@ -339,8 +339,7 @@ def test_tick_equalities(cls): @pytest.mark.parametrize("cls", tick_classes) def test_tick_offset(cls): - msg = f"{cls.__name__}.is_anchored() is deprecated and will be removed in a " - "future version, please use False instead." + msg = f"{cls.__name__}.is_anchored() is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not cls().is_anchored() diff --git a/pandas/tests/tseries/offsets/test_week.py b/pandas/tests/tseries/offsets/test_week.py index f42ff091af277..e106f00a625f1 100644 --- a/pandas/tests/tseries/offsets/test_week.py +++ b/pandas/tests/tseries/offsets/test_week.py @@ -42,10 +42,14 @@ def test_corner(self): Week(weekday=-1) def test_is_anchored(self): - assert Week(weekday=0).is_anchored() - assert not Week().is_anchored() - assert not Week(2, weekday=2).is_anchored() - assert not Week(2).is_anchored() + msg = "DateOffset.is_anchored() is deprecated and will be removed " + "in a future version, please use DateOffset.n == 1 instead." + + with pytest.raises(FutureWarning, match=msg): + assert Week(weekday=0).is_anchored() + assert not Week().is_anchored() + assert not Week(2, weekday=2).is_anchored() + assert not Week(2).is_anchored() offset_cases = [] # not business week From df78796fb45db9a789a5c080845583f74395e73a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 28 Dec 2023 13:39:43 +0100 Subject: [PATCH 3/6] fix tests --- .../tseries/offsets/test_business_quarter.py | 19 +++++++++++----- pandas/tests/tseries/offsets/test_fiscal.py | 22 +++++++++++-------- pandas/tests/tseries/offsets/test_offsets.py | 3 +-- pandas/tests/tseries/offsets/test_quarter.py | 19 +++++++++++----- pandas/tests/tseries/offsets/test_ticks.py | 2 +- pandas/tests/tseries/offsets/test_week.py | 7 +++--- 6 files changed, 45 insertions(+), 27 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_business_quarter.py b/pandas/tests/tseries/offsets/test_business_quarter.py index 44a7f16ab039d..163aee2eaf8bd 100644 --- a/pandas/tests/tseries/offsets/test_business_quarter.py +++ b/pandas/tests/tseries/offsets/test_business_quarter.py @@ -9,6 +9,7 @@ import pytest +import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, @@ -54,9 +55,12 @@ def test_repr(self): assert repr(BQuarterBegin(startingMonth=1)) == expected def test_is_anchored(self): - assert BQuarterBegin(startingMonth=1).is_anchored() - assert BQuarterBegin().is_anchored() - assert not BQuarterBegin(2, startingMonth=1).is_anchored() + msg = r"BQuarterBegin.is_anchored\(\) is deprecated " + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert BQuarterBegin(startingMonth=1).is_anchored() + assert BQuarterBegin().is_anchored() + assert not BQuarterBegin(2, startingMonth=1).is_anchored() def test_offset_corner_case(self): # corner @@ -177,9 +181,12 @@ def test_repr(self): assert repr(BQuarterEnd(startingMonth=1)) == expected def test_is_anchored(self): - assert BQuarterEnd(startingMonth=1).is_anchored() - assert BQuarterEnd().is_anchored() - assert not BQuarterEnd(2, startingMonth=1).is_anchored() + msg = r"BQuarterEnd.is_anchored\(\) is deprecated " + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert BQuarterEnd(startingMonth=1).is_anchored() + assert BQuarterEnd().is_anchored() + assert not BQuarterEnd(2, startingMonth=1).is_anchored() def test_offset_corner_case(self): # corner diff --git a/pandas/tests/tseries/offsets/test_fiscal.py b/pandas/tests/tseries/offsets/test_fiscal.py index 7f8c34bc6832e..671dedcfbc7d0 100644 --- a/pandas/tests/tseries/offsets/test_fiscal.py +++ b/pandas/tests/tseries/offsets/test_fiscal.py @@ -7,6 +7,7 @@ import pytest from pandas import Timestamp +import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( WeekDay, assert_is_on_offset, @@ -295,15 +296,18 @@ def test_apply(self): class TestFY5253LastOfMonthQuarter: def test_is_anchored(self): - assert makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 - ).is_anchored() - assert makeFY5253LastOfMonthQuarter( - weekday=WeekDay.SAT, startingMonth=3, qtr_with_extra_week=4 - ).is_anchored() - assert not makeFY5253LastOfMonthQuarter( - 2, startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 - ).is_anchored() + msg = r"FY5253Quarter.is_anchored\(\) is deprecated " + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert makeFY5253LastOfMonthQuarter( + startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + ).is_anchored() + assert makeFY5253LastOfMonthQuarter( + weekday=WeekDay.SAT, startingMonth=3, qtr_with_extra_week=4 + ).is_anchored() + assert not makeFY5253LastOfMonthQuarter( + 2, startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + ).is_anchored() def test_equality(self): assert makeFY5253LastOfMonthQuarter( diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 30eb952b11e5c..f0c167106f522 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -625,8 +625,7 @@ def test_default_constructor(self, dt): assert (dt + DateOffset(2)) == datetime(2008, 1, 4) def test_is_anchored(self): - msg = "DateOffset.is_anchored() is deprecated and will be removed " - "in a future version, please use DateOffset.n == 1 instead." + msg = r"DateOffset.is_anchored\(\) is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not DateOffset(2).is_anchored() diff --git a/pandas/tests/tseries/offsets/test_quarter.py b/pandas/tests/tseries/offsets/test_quarter.py index d183645da507d..63eca1de8420d 100644 --- a/pandas/tests/tseries/offsets/test_quarter.py +++ b/pandas/tests/tseries/offsets/test_quarter.py @@ -9,6 +9,7 @@ import pytest +import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( assert_is_on_offset, assert_offset_equal, @@ -53,9 +54,12 @@ def test_repr(self): assert repr(QuarterBegin(startingMonth=1)) == expected def test_is_anchored(self): - assert QuarterBegin(startingMonth=1).is_anchored() - assert QuarterBegin().is_anchored() - assert not QuarterBegin(2, startingMonth=1).is_anchored() + msg = r"QuarterBegin.is_anchored\(\) is deprecated " + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert QuarterBegin(startingMonth=1).is_anchored() + assert QuarterBegin().is_anchored() + assert not QuarterBegin(2, startingMonth=1).is_anchored() def test_offset_corner_case(self): # corner @@ -161,9 +165,12 @@ def test_repr(self): assert repr(QuarterEnd(startingMonth=1)) == expected def test_is_anchored(self): - assert QuarterEnd(startingMonth=1).is_anchored() - assert QuarterEnd().is_anchored() - assert not QuarterEnd(2, startingMonth=1).is_anchored() + msg = r"QuarterEnd.is_anchored\(\) is deprecated " + + with tm.assert_produces_warning(FutureWarning, match=msg): + assert QuarterEnd(startingMonth=1).is_anchored() + assert QuarterEnd().is_anchored() + assert not QuarterEnd(2, startingMonth=1).is_anchored() def test_offset_corner_case(self): # corner diff --git a/pandas/tests/tseries/offsets/test_ticks.py b/pandas/tests/tseries/offsets/test_ticks.py index 462ca112b3faf..a412ae9610a01 100644 --- a/pandas/tests/tseries/offsets/test_ticks.py +++ b/pandas/tests/tseries/offsets/test_ticks.py @@ -339,7 +339,7 @@ def test_tick_equalities(cls): @pytest.mark.parametrize("cls", tick_classes) def test_tick_offset(cls): - msg = f"{cls.__name__}.is_anchored() is deprecated " + msg = f"{cls.__name__}.is_anchored\(\) is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not cls().is_anchored() diff --git a/pandas/tests/tseries/offsets/test_week.py b/pandas/tests/tseries/offsets/test_week.py index e106f00a625f1..a417d12bc8a5b 100644 --- a/pandas/tests/tseries/offsets/test_week.py +++ b/pandas/tests/tseries/offsets/test_week.py @@ -21,6 +21,7 @@ WeekOfMonth, ) +import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( WeekDay, assert_is_on_offset, @@ -42,10 +43,10 @@ def test_corner(self): Week(weekday=-1) def test_is_anchored(self): - msg = "DateOffset.is_anchored() is deprecated and will be removed " - "in a future version, please use DateOffset.n == 1 instead." + msg = r"Week.is_anchored\(\) is deprecated and will be removed " + "in a future version, please use Week.n == 1 instead." - with pytest.raises(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): assert Week(weekday=0).is_anchored() assert not Week().is_anchored() assert not Week(2, weekday=2).is_anchored() From e70381744badf3ea789a12e4d5b9b35ee6fda6d9 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 28 Dec 2023 14:54:36 +0100 Subject: [PATCH 4/6] correct DateOffset and Tick docstrings, add notes to v2.2.0 --- doc/source/whatsnew/v2.2.0.rst | 2 ++ pandas/_libs/tslibs/offsets.pyx | 22 +++++++++++++++++++-- pandas/tests/tseries/offsets/test_fiscal.py | 2 +- pandas/tests/tseries/offsets/test_ticks.py | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 5b955aa45219a..7bf94cf4b2b93 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -584,6 +584,7 @@ Other Deprecations - Changed :meth:`Timedelta.resolution_string` to return ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``H``, ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`) - Deprecated :attr:`offsets.Day.delta`, :attr:`offsets.Hour.delta`, :attr:`offsets.Minute.delta`, :attr:`offsets.Second.delta`, :attr:`offsets.Milli.delta`, :attr:`offsets.Micro.delta`, :attr:`offsets.Nano.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`) - Deprecated :func:`pandas.api.types.is_interval` and :func:`pandas.api.types.is_period`, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`) +- Deprecated :func:`pd.DateOffset().is_anchored()`, use ``DateOffset().n == 1`` instead (:issue:`55388`) - Deprecated :func:`pd.core.internals.api.make_block`, use public APIs instead (:issue:`40226`) - Deprecated :func:`read_gbq` and :meth:`DataFrame.to_gbq`. Use ``pandas_gbq.read_gbq`` and ``pandas_gbq.to_gbq`` instead https://pandas-gbq.readthedocs.io/en/latest/api.html (:issue:`55525`) - Deprecated :meth:`.DataFrameGroupBy.fillna` and :meth:`.SeriesGroupBy.fillna`; use :meth:`.DataFrameGroupBy.ffill`, :meth:`.DataFrameGroupBy.bfill` for forward and backward filling or :meth:`.DataFrame.fillna` to fill with a single value (or the Series equivalents) (:issue:`55718`) @@ -592,6 +593,7 @@ Other Deprecations - Deprecated :meth:`Series.ravel`, the underlying array is already 1D, so ravel is not necessary (:issue:`52511`) - Deprecated :meth:`Series.resample` and :meth:`DataFrame.resample` with a :class:`PeriodIndex` (and the 'convention' keyword), convert to :class:`DatetimeIndex` (with ``.to_timestamp()``) before resampling instead (:issue:`53481`) - Deprecated :meth:`Series.view`, use :meth:`Series.astype` instead to change the dtype (:issue:`20251`) +- Deprecated :meth:`offsets.Tick().is_anchored()`, use ``False`` instead (:issue:`55388`) - Deprecated ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock``, use public APIs instead (:issue:`55139`) - Deprecated ``year``, ``month``, ``quarter``, ``day``, ``hour``, ``minute``, and ``second`` keywords in the :class:`PeriodIndex` constructor, use :meth:`PeriodIndex.from_fields` instead (:issue:`55960`) - Deprecated accepting a type as an argument in :meth:`Index.view`, call without any arguments instead (:issue:`55709`) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e73bc8173f824..26c3554b1113c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -756,11 +756,14 @@ cdef class BaseOffset: raise ValueError(f"{self} is a non-fixed frequency") def is_anchored(self) -> bool: - # TODO: Does this make sense for the general case? It would help - # if there were a canonical docstring for what is_anchored means. + # GH#55388 """ Return boolean whether the frequency is a unit frequency (n=1). + .. deprecated:: 2.2.0 + The is_anchored is deprecated and will be removed in a future version. + Do ``DateOffset().n == 1`` instead of ``DateOffset().is_anchored()``. + Examples -------- >>> pd.DateOffset().is_anchored() @@ -960,6 +963,21 @@ cdef class Tick(SingleConstructorOffset): return True def is_anchored(self) -> bool: + # GH#55388 + """ + Return False. + + .. deprecated:: 2.2.0 + The is_anchored is deprecated and will be removed in a future version. + Do ``False`` instead of ``offsets.Tick().is_anchored()``. + + Examples + -------- + >>> pd.offsets.Tick().is_anchored() + False + >>> pd.offsets.Tick(2).is_anchored() + False + """ warnings.warn( f"{type(self).__name__}.is_anchored() is deprecated and will be removed " f"in a future version, please use False instead.", diff --git a/pandas/tests/tseries/offsets/test_fiscal.py b/pandas/tests/tseries/offsets/test_fiscal.py index 671dedcfbc7d0..135641ae562b3 100644 --- a/pandas/tests/tseries/offsets/test_fiscal.py +++ b/pandas/tests/tseries/offsets/test_fiscal.py @@ -297,7 +297,7 @@ def test_apply(self): class TestFY5253LastOfMonthQuarter: def test_is_anchored(self): msg = r"FY5253Quarter.is_anchored\(\) is deprecated " - + with tm.assert_produces_warning(FutureWarning, match=msg): assert makeFY5253LastOfMonthQuarter( startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 diff --git a/pandas/tests/tseries/offsets/test_ticks.py b/pandas/tests/tseries/offsets/test_ticks.py index a412ae9610a01..8790007b2e639 100644 --- a/pandas/tests/tseries/offsets/test_ticks.py +++ b/pandas/tests/tseries/offsets/test_ticks.py @@ -339,7 +339,7 @@ def test_tick_equalities(cls): @pytest.mark.parametrize("cls", tick_classes) def test_tick_offset(cls): - msg = f"{cls.__name__}.is_anchored\(\) is deprecated " + msg = rf"{cls.__name__}.is_anchored\(\) is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not cls().is_anchored() From d031fadf30fa9830d844f29db7a608e6586fbebd Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 28 Dec 2023 15:34:12 +0100 Subject: [PATCH 5/6] fix pylint error --- pandas/tests/tseries/offsets/test_week.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_week.py b/pandas/tests/tseries/offsets/test_week.py index a417d12bc8a5b..8672de2f7c401 100644 --- a/pandas/tests/tseries/offsets/test_week.py +++ b/pandas/tests/tseries/offsets/test_week.py @@ -43,8 +43,7 @@ def test_corner(self): Week(weekday=-1) def test_is_anchored(self): - msg = r"Week.is_anchored\(\) is deprecated and will be removed " - "in a future version, please use Week.n == 1 instead." + msg = r"Week.is_anchored\(\) is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert Week(weekday=0).is_anchored() From b0d7ef47d105a1eeed197a85eb7830601db64962 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 28 Dec 2023 23:11:29 +0100 Subject: [PATCH 6/6] correct notes in v2.2.0, correct warning messages in is_anchored, remove the comment --- doc/source/whatsnew/v2.2.0.rst | 4 +-- pandas/_libs/tslibs/offsets.pyx | 34 +++++++++---------- .../indexes/interval/test_interval_range.py | 2 -- .../tseries/offsets/test_business_quarter.py | 4 +-- pandas/tests/tseries/offsets/test_fiscal.py | 2 +- pandas/tests/tseries/offsets/test_offsets.py | 2 +- pandas/tests/tseries/offsets/test_quarter.py | 4 +-- pandas/tests/tseries/offsets/test_ticks.py | 2 +- pandas/tests/tseries/offsets/test_week.py | 2 +- 9 files changed, 27 insertions(+), 29 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 7bf94cf4b2b93..3ef1abff53d18 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -584,16 +584,16 @@ Other Deprecations - Changed :meth:`Timedelta.resolution_string` to return ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``H``, ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`) - Deprecated :attr:`offsets.Day.delta`, :attr:`offsets.Hour.delta`, :attr:`offsets.Minute.delta`, :attr:`offsets.Second.delta`, :attr:`offsets.Milli.delta`, :attr:`offsets.Micro.delta`, :attr:`offsets.Nano.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`) - Deprecated :func:`pandas.api.types.is_interval` and :func:`pandas.api.types.is_period`, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`) -- Deprecated :func:`pd.DateOffset().is_anchored()`, use ``DateOffset().n == 1`` instead (:issue:`55388`) - Deprecated :func:`pd.core.internals.api.make_block`, use public APIs instead (:issue:`40226`) - Deprecated :func:`read_gbq` and :meth:`DataFrame.to_gbq`. Use ``pandas_gbq.read_gbq`` and ``pandas_gbq.to_gbq`` instead https://pandas-gbq.readthedocs.io/en/latest/api.html (:issue:`55525`) - Deprecated :meth:`.DataFrameGroupBy.fillna` and :meth:`.SeriesGroupBy.fillna`; use :meth:`.DataFrameGroupBy.ffill`, :meth:`.DataFrameGroupBy.bfill` for forward and backward filling or :meth:`.DataFrame.fillna` to fill with a single value (or the Series equivalents) (:issue:`55718`) +- Deprecated :meth:`DateOffset.is_anchored`, use ``obj.n == 1`` for non-Tick subclasses (for Tick this was always False) (:issue:`55388`) - Deprecated :meth:`DatetimeArray.__init__` and :meth:`TimedeltaArray.__init__`, use :func:`array` instead (:issue:`55623`) - Deprecated :meth:`Index.format`, use ``index.astype(str)`` or ``index.map(formatter)`` instead (:issue:`55413`) - Deprecated :meth:`Series.ravel`, the underlying array is already 1D, so ravel is not necessary (:issue:`52511`) - Deprecated :meth:`Series.resample` and :meth:`DataFrame.resample` with a :class:`PeriodIndex` (and the 'convention' keyword), convert to :class:`DatetimeIndex` (with ``.to_timestamp()``) before resampling instead (:issue:`53481`) - Deprecated :meth:`Series.view`, use :meth:`Series.astype` instead to change the dtype (:issue:`20251`) -- Deprecated :meth:`offsets.Tick().is_anchored()`, use ``False`` instead (:issue:`55388`) +- Deprecated :meth:`offsets.Tick.is_anchored`, use ``False`` instead (:issue:`55388`) - Deprecated ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock``, use public APIs instead (:issue:`55139`) - Deprecated ``year``, ``month``, ``quarter``, ``day``, ``hour``, ``minute``, and ``second`` keywords in the :class:`PeriodIndex` constructor, use :meth:`PeriodIndex.from_fields` instead (:issue:`55960`) - Deprecated accepting a type as an argument in :meth:`Index.view`, call without any arguments instead (:issue:`55709`) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 26c3554b1113c..3a339171d0da2 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -761,8 +761,8 @@ cdef class BaseOffset: Return boolean whether the frequency is a unit frequency (n=1). .. deprecated:: 2.2.0 - The is_anchored is deprecated and will be removed in a future version. - Do ``DateOffset().n == 1`` instead of ``DateOffset().is_anchored()``. + is_anchored is deprecated and will be removed in a future version. + Use ``obj.n == 1`` instead. Examples -------- @@ -772,8 +772,8 @@ cdef class BaseOffset: False """ warnings.warn( - f"{type(self).__name__}.is_anchored() is deprecated and will be removed " - f"in a future version, please use {type(self).__name__}.n == 1 instead.", + f"{type(self).__name__}.is_anchored is deprecated and will be removed " + f"in a future version, please use \'obj.n == 1\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -968,18 +968,18 @@ cdef class Tick(SingleConstructorOffset): Return False. .. deprecated:: 2.2.0 - The is_anchored is deprecated and will be removed in a future version. - Do ``False`` instead of ``offsets.Tick().is_anchored()``. + is_anchored is deprecated and will be removed in a future version. + Use ``False`` instead. Examples -------- - >>> pd.offsets.Tick().is_anchored() + >>> pd.offsets.Hour().is_anchored() False - >>> pd.offsets.Tick(2).is_anchored() + >>> pd.offsets.Hour(2).is_anchored() False """ warnings.warn( - f"{type(self).__name__}.is_anchored() is deprecated and will be removed " + f"{type(self).__name__}.is_anchored is deprecated and will be removed " f"in a future version, please use False instead.", FutureWarning, stacklevel=find_stack_level(), @@ -2694,9 +2694,9 @@ cdef class QuarterOffset(SingleConstructorOffset): def is_anchored(self) -> bool: warnings.warn( - f"{type(self).__name__}.is_anchored() is deprecated and will be removed " - f"in a future version, please use {type(self).__name__}.n == 1 " - f" and {type(self).__name__}.startingMonth is not None instead.", + f"{type(self).__name__}.is_anchored is deprecated and will be removed " + f"in a future version, please use \'obj.n == 1 " + f"and obj.startingMonth is not None\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -3346,9 +3346,9 @@ cdef class Week(SingleConstructorOffset): def is_anchored(self) -> bool: warnings.warn( - f"{type(self).__name__}.is_anchored() is deprecated and will be removed " - f"in a future version, please use {type(self).__name__}.n == 1 " - f" and {type(self).__name__}.weekday is not None instead.", + f"{type(self).__name__}.is_anchored is deprecated and will be removed " + f"in a future version, please use \'obj.n == 1 " + f"and obj.weekday is not None\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -3642,8 +3642,8 @@ cdef class FY5253Mixin(SingleConstructorOffset): def is_anchored(self) -> bool: warnings.warn( - f"{type(self).__name__}.is_anchored() is deprecated and will be removed " - f"in a future version, please use {type(self).__name__}.n == 1 instead.", + f"{type(self).__name__}.is_anchored is deprecated and will be removed " + f"in a future version, please use \'obj.n == 1\' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/indexes/interval/test_interval_range.py b/pandas/tests/indexes/interval/test_interval_range.py index eaa84b1babdc5..e8de59f84bcc6 100644 --- a/pandas/tests/indexes/interval/test_interval_range.py +++ b/pandas/tests/indexes/interval/test_interval_range.py @@ -85,8 +85,6 @@ def test_constructor_timestamp(self, closed, name, freq, periods, tz): # GH 20976: linspace behavior defined from start/end/periods if not breaks.freq.n == 1 and tz is None: - # matches expected only for non-anchored offsets and tz naive - # (anchored/DST transitions cause unequal spacing in expected) result = interval_range( start=start, end=end, periods=periods, name=name, closed=closed ) diff --git a/pandas/tests/tseries/offsets/test_business_quarter.py b/pandas/tests/tseries/offsets/test_business_quarter.py index 163aee2eaf8bd..6d7a115054b7f 100644 --- a/pandas/tests/tseries/offsets/test_business_quarter.py +++ b/pandas/tests/tseries/offsets/test_business_quarter.py @@ -55,7 +55,7 @@ def test_repr(self): assert repr(BQuarterBegin(startingMonth=1)) == expected def test_is_anchored(self): - msg = r"BQuarterBegin.is_anchored\(\) is deprecated " + msg = "BQuarterBegin.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert BQuarterBegin(startingMonth=1).is_anchored() @@ -181,7 +181,7 @@ def test_repr(self): assert repr(BQuarterEnd(startingMonth=1)) == expected def test_is_anchored(self): - msg = r"BQuarterEnd.is_anchored\(\) is deprecated " + msg = "BQuarterEnd.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert BQuarterEnd(startingMonth=1).is_anchored() diff --git a/pandas/tests/tseries/offsets/test_fiscal.py b/pandas/tests/tseries/offsets/test_fiscal.py index 135641ae562b3..824e66a1ddef1 100644 --- a/pandas/tests/tseries/offsets/test_fiscal.py +++ b/pandas/tests/tseries/offsets/test_fiscal.py @@ -296,7 +296,7 @@ def test_apply(self): class TestFY5253LastOfMonthQuarter: def test_is_anchored(self): - msg = r"FY5253Quarter.is_anchored\(\) is deprecated " + msg = "FY5253Quarter.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert makeFY5253LastOfMonthQuarter( diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index f0c167106f522..62afb8b83d576 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -625,7 +625,7 @@ def test_default_constructor(self, dt): assert (dt + DateOffset(2)) == datetime(2008, 1, 4) def test_is_anchored(self): - msg = r"DateOffset.is_anchored\(\) is deprecated " + msg = "DateOffset.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not DateOffset(2).is_anchored() diff --git a/pandas/tests/tseries/offsets/test_quarter.py b/pandas/tests/tseries/offsets/test_quarter.py index 63eca1de8420d..5fd3ba0a5fb87 100644 --- a/pandas/tests/tseries/offsets/test_quarter.py +++ b/pandas/tests/tseries/offsets/test_quarter.py @@ -54,7 +54,7 @@ def test_repr(self): assert repr(QuarterBegin(startingMonth=1)) == expected def test_is_anchored(self): - msg = r"QuarterBegin.is_anchored\(\) is deprecated " + msg = "QuarterBegin.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert QuarterBegin(startingMonth=1).is_anchored() @@ -165,7 +165,7 @@ def test_repr(self): assert repr(QuarterEnd(startingMonth=1)) == expected def test_is_anchored(self): - msg = r"QuarterEnd.is_anchored\(\) is deprecated " + msg = "QuarterEnd.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert QuarterEnd(startingMonth=1).is_anchored() diff --git a/pandas/tests/tseries/offsets/test_ticks.py b/pandas/tests/tseries/offsets/test_ticks.py index 8790007b2e639..399b7038d3426 100644 --- a/pandas/tests/tseries/offsets/test_ticks.py +++ b/pandas/tests/tseries/offsets/test_ticks.py @@ -339,7 +339,7 @@ def test_tick_equalities(cls): @pytest.mark.parametrize("cls", tick_classes) def test_tick_offset(cls): - msg = rf"{cls.__name__}.is_anchored\(\) is deprecated " + msg = f"{cls.__name__}.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert not cls().is_anchored() diff --git a/pandas/tests/tseries/offsets/test_week.py b/pandas/tests/tseries/offsets/test_week.py index 8672de2f7c401..0cd6f769769ae 100644 --- a/pandas/tests/tseries/offsets/test_week.py +++ b/pandas/tests/tseries/offsets/test_week.py @@ -43,7 +43,7 @@ def test_corner(self): Week(weekday=-1) def test_is_anchored(self): - msg = r"Week.is_anchored\(\) is deprecated " + msg = "Week.is_anchored is deprecated " with tm.assert_produces_warning(FutureWarning, match=msg): assert Week(weekday=0).is_anchored()