Skip to content

Commit

Permalink
REF: remove libfrequencies (pandas-dev#34828)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Jun 16, 2020
1 parent df6f668 commit 5fdd6f5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 59 deletions.
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/frequencies.pxd

This file was deleted.

40 changes: 0 additions & 40 deletions pandas/_libs/tslibs/frequencies.pyx

This file was deleted.

29 changes: 25 additions & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ from pandas._libs.tslibs.dtypes cimport (
attrname_to_abbrevs,
)

from pandas._libs.tslibs.frequencies cimport get_to_timestamp_base
from pandas._libs.tslibs.parsing cimport get_rule_month
from pandas._libs.tslibs.parsing import parse_time_string
from pandas._libs.tslibs.nattype cimport (
Expand Down Expand Up @@ -1478,7 +1477,30 @@ class IncompatibleFrequency(ValueError):
pass


cdef class _Period:
cdef class PeriodMixin:
# Methods shared between Period and PeriodArray

cpdef int _get_to_timestamp_base(self):
"""
Return frequency code group used for base of to_timestamp against
frequency code.
Return day freq code against longer freq than day.
Return second freq code against hour between second.
Returns
-------
int
"""
base = self._dtype._dtype_code
if base < FR_BUS:
return FR_DAY
elif FR_HR <= base <= FR_SEC:
return FR_SEC
return base


cdef class _Period(PeriodMixin):

cdef readonly:
int64_t ordinal
Expand Down Expand Up @@ -1734,8 +1756,7 @@ cdef class _Period:
return endpoint - Timedelta(1, 'ns')

if freq is None:
base = self._dtype._dtype_code
freq = get_to_timestamp_base(base)
freq = self._get_to_timestamp_base()
base = freq
else:
freq = self._maybe_convert_freq(freq)
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
NaTType,
Timedelta,
delta_to_nanoseconds,
frequencies as libfrequencies,
iNaT,
period as libperiod,
to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import Tick, delta_to_tick
from pandas._libs.tslibs.period import (
DIFFERENT_FREQ,
IncompatibleFrequency,
Period,
PeriodMixin,
get_period_field_arr,
period_asfreq_arr,
)
Expand Down Expand Up @@ -61,7 +62,7 @@ def f(self):
return property(f)


class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
class PeriodArray(PeriodMixin, dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
"""
Pandas ExtensionArray for storing Period data.
Expand Down Expand Up @@ -440,8 +441,7 @@ def to_timestamp(self, freq=None, how="start"):
return (self + self.freq).to_timestamp(how="start") - adjust

if freq is None:
base = self.freq._period_dtype_code
freq = libfrequencies.get_to_timestamp_base(base)
freq = self._get_to_timestamp_base()
base = freq
else:
freq = Period._maybe_convert_freq(freq)
Expand Down Expand Up @@ -1027,11 +1027,11 @@ def _range_from_fields(
if quarter is not None:
if freq is None:
freq = to_offset("Q")
base = libfrequencies.FreqGroup.FR_QTR
base = FreqGroup.FR_QTR
else:
freq = to_offset(freq)
base = libperiod.freq_to_dtype_code(freq)
if base != libfrequencies.FreqGroup.FR_QTR:
if base != FreqGroup.FR_QTR:
raise AssertionError("base must equal FR_QTR")

year, quarter = _make_field_arrays(year, quarter)
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

from pandas._libs.tslibs import Period, to_offset
from pandas._libs.tslibs.frequencies import FreqGroup
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._typing import FrameOrSeriesUnion

from pandas.core.dtypes.generic import (
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/tseries/frequencies/test_freq_code.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import pytest

from pandas._libs.tslibs import Resolution, to_offset
from pandas._libs.tslibs import Period, Resolution, to_offset
from pandas._libs.tslibs.dtypes import _attrname_to_abbrevs
from pandas._libs.tslibs.frequencies import get_to_timestamp_base


@pytest.mark.parametrize(
"freqstr,exp_freqstr",
[("D", "D"), ("W", "D"), ("M", "D"), ("S", "S"), ("T", "S"), ("H", "S")],
)
def test_get_to_timestamp_base(freqstr, exp_freqstr):
left_code = to_offset(freqstr)._period_dtype_code
off = to_offset(freqstr)
per = Period._from_ordinal(1, off)
exp_code = to_offset(exp_freqstr)._period_dtype_code
assert get_to_timestamp_base(left_code) == exp_code

result_code = per._get_to_timestamp_base()
assert result_code == exp_code


@pytest.mark.parametrize(
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def test_namespace():
"conversion",
"dtypes",
"fields",
"frequencies",
"nattype",
"np_datetime",
"offsets",
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ class CheckSDist(sdist_class):
"pandas/_libs/tslibs/conversion.pyx",
"pandas/_libs/tslibs/fields.pyx",
"pandas/_libs/tslibs/offsets.pyx",
"pandas/_libs/tslibs/frequencies.pyx",
"pandas/_libs/tslibs/resolution.pyx",
"pandas/_libs/tslibs/parsing.pyx",
"pandas/_libs/tslibs/tzconversion.pyx",
Expand Down Expand Up @@ -615,7 +614,6 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
"pyxfile": "_libs/tslibs/fields",
"depends": tseries_depends,
},
"_libs.tslibs.frequencies": {"pyxfile": "_libs/tslibs/frequencies"},
"_libs.tslibs.nattype": {"pyxfile": "_libs/tslibs/nattype"},
"_libs.tslibs.np_datetime": {
"pyxfile": "_libs/tslibs/np_datetime",
Expand Down

0 comments on commit 5fdd6f5

Please sign in to comment.