-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: the method is_anchored() for offsets #56594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
287fdef
8c870f6
df78796
005198b
e703817
d031fad
b0d7ef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no parentheses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for reviewing this PR. I removed the parentheses |
||
- 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`) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -756,18 +756,27 @@ 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The is_anchored is deprecated" -> "is_anchored is deprecated" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's done |
||
Do ``DateOffset().n == 1`` instead of ``DateOffset().is_anchored()``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Use obj.n == 1" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
Examples | ||
-------- | ||
>>> pd.DateOffset().is_anchored() | ||
True | ||
>>> 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.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {type(self).name}.n -> obj.n There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
return self.n == 1 | ||
|
||
# ------------------------------------------------------------------ | ||
|
@@ -954,6 +963,27 @@ 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tick should never be initialized directly; use a subclass here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you, I will use Hour |
||
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.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
return False | ||
|
||
# This is identical to BaseOffset.__hash__, but has to be redefined here | ||
|
@@ -2663,6 +2693,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 +3345,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 +3641,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 | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment here refers to anchoring. i suspect the comment (which i suspect i wrote) misunderstood what "is_anchored" really meant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, I removed the comment |
||
# (anchored/DST transitions cause unequal spacing in expected) | ||
result = interval_range( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:meth:
DateOffset.is_anchored
, use ``obj.n == 1` for non-Tick subclasses (for Tick this was always False)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I did as you suggested