Skip to content

Commit d105ce2

Browse files
jbrockmendeljreback
authored andcommitted
use liboffsets to_offset function (#21693)
1 parent dc45fba commit d105ce2

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

pandas/_libs/tslib.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ from tslibs.conversion import tz_convert_single
5151
from tslibs.nattype import NaT, nat_strings, iNaT
5252
from tslibs.nattype cimport checknull_with_nat, NPY_NAT
5353

54+
from tslibs.offsets cimport to_offset
55+
5456
from tslibs.timestamps cimport (create_timestamp_from_ts,
5557
_NS_UPPER_BOUND, _NS_LOWER_BOUND)
5658
from tslibs.timestamps import Timestamp
@@ -118,7 +120,6 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None,
118120
func_create = create_timestamp_from_ts
119121

120122
if is_string_object(freq):
121-
from pandas.tseries.frequencies import to_offset
122123
freq = to_offset(freq)
123124
elif box == "time":
124125
func_create = create_time_from_ts

pandas/_libs/tslibs/offsets.pxd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
cdef to_offset(object obj)

pandas/_libs/tslibs/period.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ from parsing import parse_time_string, NAT_SENTINEL
5555
from resolution import Resolution
5656
from nattype import nat_strings, NaT, iNaT
5757
from nattype cimport _nat_scalar_rules, NPY_NAT
58+
from offsets cimport to_offset
5859

5960
from pandas.tseries import offsets
60-
from pandas.tseries import frequencies
6161

6262

6363
cdef extern from "period_helper.h":
@@ -1015,7 +1015,7 @@ cdef class _Period(object):
10151015
code, stride = get_freq_code(freq)
10161016
freq = get_freq_str(code, stride)
10171017

1018-
freq = frequencies.to_offset(freq)
1018+
freq = to_offset(freq)
10191019

10201020
if freq.n <= 0:
10211021
raise ValueError('Frequency must be positive, because it'
@@ -1063,7 +1063,7 @@ cdef class _Period(object):
10631063

10641064
if (PyDelta_Check(other) or util.is_timedelta64_object(other) or
10651065
isinstance(other, offsets.Tick)):
1066-
offset = frequencies.to_offset(self.freq.rule_code)
1066+
offset = to_offset(self.freq.rule_code)
10671067
if isinstance(offset, offsets.Tick):
10681068
nanos = delta_to_nanoseconds(other)
10691069
offset_nanos = delta_to_nanoseconds(offset)

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ from np_datetime cimport (cmp_scalar, reverse_ops, td64_to_tdstruct,
3333

3434
from nattype import nat_strings, NaT
3535
from nattype cimport checknull_with_nat, NPY_NAT
36+
from offsets cimport to_offset
3637

3738
# ----------------------------------------------------------------------
3839
# Constants
@@ -1050,7 +1051,6 @@ class Timedelta(_Timedelta):
10501051
cdef:
10511052
int64_t result, unit
10521053

1053-
from pandas.tseries.frequencies import to_offset
10541054
unit = to_offset(freq).nanos
10551055
result = unit * rounder(self.value / float(unit))
10561056
return Timedelta(result, unit='ns')

pandas/_libs/tslibs/timestamps.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ from nattype cimport NPY_NAT
3030
from np_datetime import OutOfBoundsDatetime
3131
from np_datetime cimport (reverse_ops, cmp_scalar, check_dts_bounds,
3232
pandas_datetimestruct, dt64_to_dtstruct)
33+
from offsets cimport to_offset
3334
from timedeltas import Timedelta
3435
from timedeltas cimport delta_to_nanoseconds
3536
from timezones cimport (
@@ -59,7 +60,6 @@ cdef inline object create_timestamp_from_ts(int64_t value,
5960

6061

6162
def round_ns(values, rounder, freq):
62-
6363
"""
6464
Applies rounding function at given frequency
6565
@@ -73,8 +73,6 @@ def round_ns(values, rounder, freq):
7373
-------
7474
:obj:`ndarray`
7575
"""
76-
77-
from pandas.tseries.frequencies import to_offset
7876
unit = to_offset(freq).nanos
7977

8078
# GH21262 If the Timestamp is multiple of the freq str

setup.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ def pxd(name):
538538
'_libs/tslibs/ccalendar',
539539
'_libs/tslibs/timedeltas',
540540
'_libs/tslibs/timezones',
541-
'_libs/tslibs/nattype'],
541+
'_libs/tslibs/nattype',
542+
'_libs/tslibs/offsets'],
542543
'depends': tseries_depends + ['pandas/_libs/src/period_helper.h'],
543544
'sources': np_datetime_sources + ['pandas/_libs/src/period_helper.c']},
544545
'_libs.properties': {
@@ -560,7 +561,8 @@ def pxd(name):
560561
'_libs/tslibs/timedeltas',
561562
'_libs/tslibs/timestamps',
562563
'_libs/tslibs/timezones',
563-
'_libs/tslibs/nattype'],
564+
'_libs/tslibs/nattype',
565+
'_libs/tslibs/offsets'],
564566
'depends': tseries_depends,
565567
'sources': np_datetime_sources},
566568
'_libs.tslibs.ccalendar': {
@@ -619,7 +621,8 @@ def pxd(name):
619621
'_libs.tslibs.timedeltas': {
620622
'pyxfile': '_libs/tslibs/timedeltas',
621623
'pxdfiles': ['_libs/src/util',
622-
'_libs/tslibs/nattype'],
624+
'_libs/tslibs/nattype',
625+
'_libs/tslibs/offsets'],
623626
'depends': np_datetime_headers,
624627
'sources': np_datetime_sources},
625628
'_libs.tslibs.timestamps': {
@@ -628,6 +631,7 @@ def pxd(name):
628631
'_libs/tslibs/ccalendar',
629632
'_libs/tslibs/conversion',
630633
'_libs/tslibs/nattype',
634+
'_libs/tslibs/offsets',
631635
'_libs/tslibs/timedeltas',
632636
'_libs/tslibs/timezones'],
633637
'depends': tseries_depends,

0 commit comments

Comments
 (0)