Skip to content

Commit 9954f9e

Browse files
authored
CLN: simplify freq/nanos checks (#34219)
1 parent 6f065b6 commit 9954f9e

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

pandas/core/arrays/period.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,7 @@ def _check_timedeltalike_freq_compat(self, other):
746746
IncompatibleFrequency
747747
"""
748748
assert isinstance(self.freq, Tick) # checked by calling function
749-
own_offset = frequencies.to_offset(self.freq.rule_code)
750-
base_nanos = delta_to_nanoseconds(own_offset)
749+
base_nanos = self.freq.base.nanos
751750

752751
if isinstance(other, (timedelta, np.timedelta64, Tick)):
753752
nanos = delta_to_nanoseconds(other)

pandas/core/indexes/period.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pandas._libs import index as libindex
77
from pandas._libs.lib import no_default
8-
from pandas._libs.tslibs import Period, frequencies as libfrequencies, resolution
8+
from pandas._libs.tslibs import Period, resolution
99
from pandas._libs.tslibs.parsing import parse_time_string
1010
from pandas._typing import DtypeObj, Label
1111
from pandas.util._decorators import Appender, cache_readonly, doc
@@ -44,7 +44,6 @@
4444
from pandas.core.ops import get_op_result_name
4545
from pandas.core.tools.datetimes import DateParseError
4646

47-
from pandas.tseries import frequencies
4847
from pandas.tseries.offsets import DateOffset, Tick
4948

5049
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
@@ -278,15 +277,12 @@ def _maybe_convert_timedelta(self, other):
278277
of self.freq. Note IncompatibleFrequency subclasses ValueError.
279278
"""
280279
if isinstance(other, (timedelta, np.timedelta64, Tick, np.ndarray)):
281-
offset = frequencies.to_offset(self.freq.rule_code)
282-
if isinstance(offset, Tick):
280+
if isinstance(self.freq, Tick):
283281
# _check_timedeltalike_freq_compat will raise if incompatible
284282
delta = self._data._check_timedeltalike_freq_compat(other)
285283
return delta
286284
elif isinstance(other, DateOffset):
287-
freqstr = other.rule_code
288-
base = libfrequencies.get_base_alias(freqstr)
289-
if base == self.freq.rule_code:
285+
if other.base == self.freq.base:
290286
return other.n
291287

292288
raise raise_on_incompatible(self, other)

0 commit comments

Comments
 (0)