Skip to content

Commit a493fe1

Browse files
authored
CLN: stronger typing for Period.freq (pandas-dev#34523)
1 parent 8c66220 commit a493fe1

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

pandas/_libs/tslibs/offsets.pxd

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
from numpy cimport int64_t
2+
13
cpdef to_offset(object obj)
24
cdef bint is_offset_object(object obj)
35
cdef bint is_tick_object(object obj)
6+
7+
cdef class BaseOffset:
8+
cdef readonly:
9+
int64_t n
10+
bint normalize
11+
dict _cache

pandas/_libs/tslibs/offsets.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ cdef class BaseOffset:
366366
_adjust_dst = True
367367
_deprecations = frozenset(["isAnchored", "onOffset"])
368368

369-
cdef readonly:
370-
int64_t n
371-
bint normalize
372-
dict _cache
369+
# cdef readonly:
370+
# int64_t n
371+
# bint normalize
372+
# dict _cache
373373

374374
def __init__(self, n=1, normalize=False):
375375
n = self._validate_n(n)

pandas/_libs/tslibs/period.pyx

+6-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ from pandas._libs.tslibs.nattype cimport (
6969
c_nat_strings as nat_strings,
7070
)
7171
from pandas._libs.tslibs.offsets cimport (
72-
to_offset, is_tick_object, is_offset_object,
72+
BaseOffset,
73+
to_offset,
74+
is_tick_object,
75+
is_offset_object,
7376
)
7477
from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal
7578

@@ -1509,9 +1512,9 @@ cdef class _Period:
15091512

15101513
cdef readonly:
15111514
int64_t ordinal
1512-
object freq
1515+
BaseOffset freq
15131516

1514-
def __cinit__(self, ordinal, freq):
1517+
def __cinit__(self, int64_t ordinal, BaseOffset freq):
15151518
self.ordinal = ordinal
15161519
self.freq = freq
15171520

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ class Timedelta(_Timedelta):
12051205
cdef:
12061206
int64_t result, unit
12071207

1208-
from pandas.tseries.frequencies import to_offset
1208+
from pandas._libs.tslibs.offsets import to_offset
12091209
unit = to_offset(freq).nanos
12101210
result = unit * rounder(self.value / float(unit))
12111211
return Timedelta(result, unit='ns')

0 commit comments

Comments
 (0)