Skip to content

Commit

Permalink
correct DateOffset and Tick docstrings, add notes to v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
natmokval committed Dec 28, 2023
1 parent 005198b commit e703817
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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`)
Expand Down
22 changes: 20 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tseries/offsets/test_fiscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tseries/offsets/test_ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e703817

Please sign in to comment.