Skip to content

use liboffsets to_offset function #21693

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

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ from tslibs.conversion import tz_convert_single
from tslibs.nattype import NaT, nat_strings, iNaT
from tslibs.nattype cimport checknull_with_nat, NPY_NAT

from tslibs.offsets cimport to_offset

from tslibs.timestamps cimport (create_timestamp_from_ts,
_NS_UPPER_BOUND, _NS_LOWER_BOUND)
from tslibs.timestamps import Timestamp
Expand Down Expand Up @@ -118,7 +120,6 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None,
func_create = create_timestamp_from_ts

if is_string_object(freq):
from pandas.tseries.frequencies import to_offset
freq = to_offset(freq)
elif box == "time":
func_create = create_time_from_ts
Expand Down
3 changes: 3 additions & 0 deletions pandas/_libs/tslibs/offsets.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

cdef to_offset(object obj)
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ from parsing import parse_time_string, NAT_SENTINEL
from resolution import Resolution
from nattype import nat_strings, NaT, iNaT
from nattype cimport _nat_scalar_rules, NPY_NAT
from offsets cimport to_offset

from pandas.tseries import offsets
from pandas.tseries import frequencies


cdef extern from "period_helper.h":
Expand Down Expand Up @@ -1015,7 +1015,7 @@ cdef class _Period(object):
code, stride = get_freq_code(freq)
freq = get_freq_str(code, stride)

freq = frequencies.to_offset(freq)
freq = to_offset(freq)

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

if (PyDelta_Check(other) or util.is_timedelta64_object(other) or
isinstance(other, offsets.Tick)):
offset = frequencies.to_offset(self.freq.rule_code)
offset = to_offset(self.freq.rule_code)
if isinstance(offset, offsets.Tick):
nanos = delta_to_nanoseconds(other)
offset_nanos = delta_to_nanoseconds(offset)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ from np_datetime cimport (cmp_scalar, reverse_ops, td64_to_tdstruct,

from nattype import nat_strings, NaT
from nattype cimport checknull_with_nat, NPY_NAT
from offsets cimport to_offset

# ----------------------------------------------------------------------
# Constants
Expand Down Expand Up @@ -1050,7 +1051,6 @@ class Timedelta(_Timedelta):
cdef:
int64_t result, unit

from pandas.tseries.frequencies import to_offset
unit = to_offset(freq).nanos
result = unit * rounder(self.value / float(unit))
return Timedelta(result, unit='ns')
Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from nattype cimport NPY_NAT
from np_datetime import OutOfBoundsDatetime
from np_datetime cimport (reverse_ops, cmp_scalar, check_dts_bounds,
pandas_datetimestruct, dt64_to_dtstruct)
from offsets cimport to_offset
from timedeltas import Timedelta
from timedeltas cimport delta_to_nanoseconds
from timezones cimport (
Expand Down Expand Up @@ -59,7 +60,6 @@ cdef inline object create_timestamp_from_ts(int64_t value,


def round_ns(values, rounder, freq):

"""
Applies rounding function at given frequency

Expand All @@ -73,8 +73,6 @@ def round_ns(values, rounder, freq):
-------
:obj:`ndarray`
"""

from pandas.tseries.frequencies import to_offset
unit = to_offset(freq).nanos

# GH21262 If the Timestamp is multiple of the freq str
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ def pxd(name):
'_libs/tslibs/ccalendar',
'_libs/tslibs/timedeltas',
'_libs/tslibs/timezones',
'_libs/tslibs/nattype'],
'_libs/tslibs/nattype',
'_libs/tslibs/offsets'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback I thought we had made the "pxdfiles" obsolete when moving to cythonize. Am I remembering wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, thought I was commenting on an open PR, not an old one.

'depends': tseries_depends + ['pandas/_libs/src/period_helper.h'],
'sources': np_datetime_sources + ['pandas/_libs/src/period_helper.c']},
'_libs.properties': {
Expand All @@ -560,7 +561,8 @@ def pxd(name):
'_libs/tslibs/timedeltas',
'_libs/tslibs/timestamps',
'_libs/tslibs/timezones',
'_libs/tslibs/nattype'],
'_libs/tslibs/nattype',
'_libs/tslibs/offsets'],
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.ccalendar': {
Expand Down Expand Up @@ -619,7 +621,8 @@ def pxd(name):
'_libs.tslibs.timedeltas': {
'pyxfile': '_libs/tslibs/timedeltas',
'pxdfiles': ['_libs/src/util',
'_libs/tslibs/nattype'],
'_libs/tslibs/nattype',
'_libs/tslibs/offsets'],
'depends': np_datetime_headers,
'sources': np_datetime_sources},
'_libs.tslibs.timestamps': {
Expand All @@ -628,6 +631,7 @@ def pxd(name):
'_libs/tslibs/ccalendar',
'_libs/tslibs/conversion',
'_libs/tslibs/nattype',
'_libs/tslibs/offsets',
'_libs/tslibs/timedeltas',
'_libs/tslibs/timezones'],
'depends': tseries_depends,
Expand Down