Skip to content

CLN: stronger typing for Period.freq #34523

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
Jun 2, 2020
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
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/offsets.pxd
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from numpy cimport int64_t

cpdef to_offset(object obj)
cdef bint is_offset_object(object obj)
cdef bint is_tick_object(object obj)

cdef class BaseOffset:
cdef readonly:
int64_t n
bint normalize
dict _cache
8 changes: 4 additions & 4 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ cdef class BaseOffset:
_adjust_dst = True
_deprecations = frozenset(["isAnchored", "onOffset"])

cdef readonly:
int64_t n
bint normalize
dict _cache
# cdef readonly:
# int64_t n
# bint normalize
# dict _cache

def __init__(self, n=1, normalize=False):
n = self._validate_n(n)
Expand Down
9 changes: 6 additions & 3 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ from pandas._libs.tslibs.nattype cimport (
c_nat_strings as nat_strings,
)
from pandas._libs.tslibs.offsets cimport (
to_offset, is_tick_object, is_offset_object,
BaseOffset,
to_offset,
is_tick_object,
is_offset_object,
)
from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal

Expand Down Expand Up @@ -1509,9 +1512,9 @@ cdef class _Period:

cdef readonly:
int64_t ordinal
object freq
BaseOffset freq

def __cinit__(self, ordinal, freq):
def __cinit__(self, int64_t ordinal, BaseOffset freq):
self.ordinal = ordinal
self.freq = freq

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 @@ -1205,7 +1205,7 @@ class Timedelta(_Timedelta):
cdef:
int64_t result, unit

from pandas.tseries.frequencies import to_offset
from pandas._libs.tslibs.offsets import to_offset
unit = to_offset(freq).nanos
result = unit * rounder(self.value / float(unit))
return Timedelta(result, unit='ns')
Expand Down