Skip to content

Commit 290988f

Browse files
jbrockmendelPuneethaPai
authored andcommitted
CLN: tslibs typing, avoid private funcs (pandas-dev#34195)
1 parent 48e3f9f commit 290988f

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

pandas/_libs/tslib.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
4242
from pandas._libs.tslibs.parsing import parse_datetime_string
4343

4444
from pandas._libs.tslibs.timedeltas cimport cast_from_unit
45-
from pandas._libs.tslibs.timezones cimport is_utc, is_tzlocal, get_dst_info
46-
from pandas._libs.tslibs.timezones import UTC
45+
from pandas._libs.tslibs.timezones cimport (
46+
get_dst_info,
47+
is_utc,
48+
is_tzlocal,
49+
utc_pytz as UTC,
50+
)
4751
from pandas._libs.tslibs.conversion cimport (
4852
_TSObject, convert_datetime_to_tsobject,
4953
get_datetime64_nanos)

pandas/_libs/tslibs/conversion.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ from pandas._libs.tslibs.nattype cimport (
4242

4343
from pandas._libs.tslibs.tzconversion import tz_localize_to_utc
4444
from pandas._libs.tslibs.tzconversion cimport (
45-
_tz_convert_tzlocal_utc, _tz_convert_tzlocal_fromutc,
46-
tz_convert_single
45+
tz_convert_utc_to_tzlocal,
46+
_tz_convert_tzlocal_fromutc,
47+
tz_convert_single,
4748
)
4849

4950
# ----------------------------------------------------------------------
@@ -706,8 +707,7 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz):
706707
result : int64 ndarray of converted of normalized nanosecond timestamps
707708
"""
708709
cdef:
709-
Py_ssize_t n = len(stamps)
710-
int64_t[:] result = np.empty(n, dtype=np.int64)
710+
int64_t[:] result
711711

712712
result = _normalize_local(stamps, tz)
713713

@@ -746,7 +746,7 @@ cdef int64_t[:] _normalize_local(const int64_t[:] stamps, tzinfo tz):
746746
if stamps[i] == NPY_NAT:
747747
result[i] = NPY_NAT
748748
continue
749-
local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False)
749+
local_val = tz_convert_utc_to_tzlocal(stamps[i], tz)
750750
dt64_to_dtstruct(local_val, &dts)
751751
result[i] = _normalized_stamp(&dts)
752752
else:
@@ -827,7 +827,7 @@ def is_date_array_normalized(const int64_t[:] stamps, object tz=None):
827827
return False
828828
elif is_tzlocal(tz):
829829
for i in range(n):
830-
local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False)
830+
local_val = tz_convert_utc_to_tzlocal(stamps[i], tz)
831831
dt64_to_dtstruct(local_val, &dts)
832832
if (dts.hour + dts.min + dts.sec + dts.us) > 0:
833833
return False

pandas/_libs/tslibs/timezones.pxd

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ cpdef bint is_utc(object tz)
66
cdef bint is_tzlocal(object tz)
77

88
cdef bint treat_tz_as_pytz(object tz)
9-
cdef bint treat_tz_as_dateutil(object tz)
109

1110
cpdef bint tz_compare(object start, object end)
1211
cpdef object get_timezone(object tz)
1312
cpdef object maybe_get_tz(object tz)
1413

1514
cdef get_utcoffset(tzinfo tz, obj)
16-
cdef bint is_fixed_offset(object tz)
15+
cdef bint is_fixed_offset(tzinfo tz)
1716

1817
cdef object get_dst_info(object tz)

pandas/_libs/tslibs/timezones.pyx

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ from datetime import timezone
33

44
# dateutil compat
55
from dateutil.tz import (
6+
gettz as dateutil_gettz,
67
tzfile as _dateutil_tzfile,
78
tzlocal as _dateutil_tzlocal,
89
tzutc as _dateutil_tzutc,
910
)
1011

1112

12-
from dateutil.tz import gettz as dateutil_gettz
13-
1413
from pytz.tzinfo import BaseTzInfo as _pytz_BaseTzInfo
1514
import pytz
1615
UTC = pytz.utc
@@ -161,7 +160,7 @@ cdef get_utcoffset(tzinfo tz, obj):
161160
return tz.utcoffset(obj)
162161

163162

164-
cdef inline bint is_fixed_offset(object tz):
163+
cdef inline bint is_fixed_offset(tzinfo tz):
165164
if treat_tz_as_dateutil(tz):
166165
if len(tz._trans_idx) == 0 and len(tz._trans_list) == 0:
167166
return 1
@@ -178,7 +177,7 @@ cdef inline bint is_fixed_offset(object tz):
178177
return 1
179178

180179

181-
cdef object get_utc_trans_times_from_dateutil_tz(object tz):
180+
cdef object _get_utc_trans_times_from_dateutil_tz(tzinfo tz):
182181
"""
183182
Transition times in dateutil timezones are stored in local non-dst
184183
time. This code converts them to UTC. It's the reverse of the code
@@ -240,7 +239,7 @@ cdef object get_dst_info(object tz):
240239
elif treat_tz_as_dateutil(tz):
241240
if len(tz._trans_list):
242241
# get utc trans times
243-
trans_list = get_utc_trans_times_from_dateutil_tz(tz)
242+
trans_list = _get_utc_trans_times_from_dateutil_tz(tz)
244243
trans = np.hstack([
245244
np.array([0], dtype='M8[s]'), # place holder for 1st item
246245
np.array(trans_list, dtype='M8[s]')]).astype(

pandas/_libs/tslibs/tzconversion.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ from numpy cimport int64_t
33

44

55
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz)
6-
cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=*)
76
cdef int64_t _tz_convert_tzlocal_fromutc(int64_t val, tzinfo tz, bint *fold)
87
cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2)

pandas/_libs/tslibs/util.pxd

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ cdef extern from "Python.h":
2323
# thus they cannot be declared 'nogil'. Also PyUnicode_AsUTF8AndSize() can
2424
# potentially allocate memory inside in unlikely case of when underlying
2525
# unicode object was stored as non-utf8 and utf8 wasn't requested before.
26-
bint PyBytes_AsStringAndSize(object obj, char** buf,
27-
Py_ssize_t* length) except -1
2826
const char* PyUnicode_AsUTF8AndSize(object obj,
2927
Py_ssize_t* length) except NULL
3028

0 commit comments

Comments
 (0)