Skip to content

Commit 5fdd6f5

Browse files
authored
REF: remove libfrequencies (#34828)
1 parent df6f668 commit 5fdd6f5

File tree

8 files changed

+38
-59
lines changed

8 files changed

+38
-59
lines changed

pandas/_libs/tslibs/frequencies.pxd

-1
This file was deleted.

pandas/_libs/tslibs/frequencies.pyx

-40
This file was deleted.

pandas/_libs/tslibs/period.pyx

+25-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ from pandas._libs.tslibs.dtypes cimport (
7474
attrname_to_abbrevs,
7575
)
7676

77-
from pandas._libs.tslibs.frequencies cimport get_to_timestamp_base
7877
from pandas._libs.tslibs.parsing cimport get_rule_month
7978
from pandas._libs.tslibs.parsing import parse_time_string
8079
from pandas._libs.tslibs.nattype cimport (
@@ -1478,7 +1477,30 @@ class IncompatibleFrequency(ValueError):
14781477
pass
14791478

14801479

1481-
cdef class _Period:
1480+
cdef class PeriodMixin:
1481+
# Methods shared between Period and PeriodArray
1482+
1483+
cpdef int _get_to_timestamp_base(self):
1484+
"""
1485+
Return frequency code group used for base of to_timestamp against
1486+
frequency code.
1487+
1488+
Return day freq code against longer freq than day.
1489+
Return second freq code against hour between second.
1490+
1491+
Returns
1492+
-------
1493+
int
1494+
"""
1495+
base = self._dtype._dtype_code
1496+
if base < FR_BUS:
1497+
return FR_DAY
1498+
elif FR_HR <= base <= FR_SEC:
1499+
return FR_SEC
1500+
return base
1501+
1502+
1503+
cdef class _Period(PeriodMixin):
14821504

14831505
cdef readonly:
14841506
int64_t ordinal
@@ -1734,8 +1756,7 @@ cdef class _Period:
17341756
return endpoint - Timedelta(1, 'ns')
17351757

17361758
if freq is None:
1737-
base = self._dtype._dtype_code
1738-
freq = get_to_timestamp_base(base)
1759+
freq = self._get_to_timestamp_base()
17391760
base = freq
17401761
else:
17411762
freq = self._maybe_convert_freq(freq)

pandas/core/arrays/period.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
NaTType,
1010
Timedelta,
1111
delta_to_nanoseconds,
12-
frequencies as libfrequencies,
1312
iNaT,
1413
period as libperiod,
1514
to_offset,
1615
)
16+
from pandas._libs.tslibs.dtypes import FreqGroup
1717
from pandas._libs.tslibs.fields import isleapyear_arr
1818
from pandas._libs.tslibs.offsets import Tick, delta_to_tick
1919
from pandas._libs.tslibs.period import (
2020
DIFFERENT_FREQ,
2121
IncompatibleFrequency,
2222
Period,
23+
PeriodMixin,
2324
get_period_field_arr,
2425
period_asfreq_arr,
2526
)
@@ -61,7 +62,7 @@ def f(self):
6162
return property(f)
6263

6364

64-
class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
65+
class PeriodArray(PeriodMixin, dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
6566
"""
6667
Pandas ExtensionArray for storing Period data.
6768
@@ -440,8 +441,7 @@ def to_timestamp(self, freq=None, how="start"):
440441
return (self + self.freq).to_timestamp(how="start") - adjust
441442

442443
if freq is None:
443-
base = self.freq._period_dtype_code
444-
freq = libfrequencies.get_to_timestamp_base(base)
444+
freq = self._get_to_timestamp_base()
445445
base = freq
446446
else:
447447
freq = Period._maybe_convert_freq(freq)
@@ -1027,11 +1027,11 @@ def _range_from_fields(
10271027
if quarter is not None:
10281028
if freq is None:
10291029
freq = to_offset("Q")
1030-
base = libfrequencies.FreqGroup.FR_QTR
1030+
base = FreqGroup.FR_QTR
10311031
else:
10321032
freq = to_offset(freq)
10331033
base = libperiod.freq_to_dtype_code(freq)
1034-
if base != libfrequencies.FreqGroup.FR_QTR:
1034+
if base != FreqGroup.FR_QTR:
10351035
raise AssertionError("base must equal FR_QTR")
10361036

10371037
year, quarter = _make_field_arrays(year, quarter)

pandas/plotting/_matplotlib/timeseries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
from pandas._libs.tslibs import Period, to_offset
9-
from pandas._libs.tslibs.frequencies import FreqGroup
9+
from pandas._libs.tslibs.dtypes import FreqGroup
1010
from pandas._typing import FrameOrSeriesUnion
1111

1212
from pandas.core.dtypes.generic import (

pandas/tests/tseries/frequencies/test_freq_code.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import pytest
22

3-
from pandas._libs.tslibs import Resolution, to_offset
3+
from pandas._libs.tslibs import Period, Resolution, to_offset
44
from pandas._libs.tslibs.dtypes import _attrname_to_abbrevs
5-
from pandas._libs.tslibs.frequencies import get_to_timestamp_base
65

76

87
@pytest.mark.parametrize(
98
"freqstr,exp_freqstr",
109
[("D", "D"), ("W", "D"), ("M", "D"), ("S", "S"), ("T", "S"), ("H", "S")],
1110
)
1211
def test_get_to_timestamp_base(freqstr, exp_freqstr):
13-
left_code = to_offset(freqstr)._period_dtype_code
12+
off = to_offset(freqstr)
13+
per = Period._from_ordinal(1, off)
1414
exp_code = to_offset(exp_freqstr)._period_dtype_code
15-
assert get_to_timestamp_base(left_code) == exp_code
15+
16+
result_code = per._get_to_timestamp_base()
17+
assert result_code == exp_code
1618

1719

1820
@pytest.mark.parametrize(

pandas/tests/tslibs/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def test_namespace():
1111
"conversion",
1212
"dtypes",
1313
"fields",
14-
"frequencies",
1514
"nattype",
1615
"np_datetime",
1716
"offsets",

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ class CheckSDist(sdist_class):
319319
"pandas/_libs/tslibs/conversion.pyx",
320320
"pandas/_libs/tslibs/fields.pyx",
321321
"pandas/_libs/tslibs/offsets.pyx",
322-
"pandas/_libs/tslibs/frequencies.pyx",
323322
"pandas/_libs/tslibs/resolution.pyx",
324323
"pandas/_libs/tslibs/parsing.pyx",
325324
"pandas/_libs/tslibs/tzconversion.pyx",
@@ -615,7 +614,6 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
615614
"pyxfile": "_libs/tslibs/fields",
616615
"depends": tseries_depends,
617616
},
618-
"_libs.tslibs.frequencies": {"pyxfile": "_libs/tslibs/frequencies"},
619617
"_libs.tslibs.nattype": {"pyxfile": "_libs/tslibs/nattype"},
620618
"_libs.tslibs.np_datetime": {
621619
"pyxfile": "_libs/tslibs/np_datetime",

0 commit comments

Comments
 (0)