Skip to content

Commit 37cd5e0

Browse files
mroeschkePingviinituutti
authored andcommitted
CLN: Add missing types to tslibs/conversion.pyx (pandas-dev#23984)
1 parent 7cf3742 commit 37cd5e0

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

pandas/_libs/tslibs/conversion.pyx

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from cython import Py_ssize_t
44

55
import numpy as np
66
cimport numpy as cnp
7-
from numpy cimport int64_t, int32_t, ndarray
7+
from numpy cimport uint8_t, int64_t, int32_t, ndarray
88
cnp.import_array()
99

1010
import pytz
@@ -535,6 +535,7 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz):
535535
int64_t[:] deltas
536536
int64_t local_val
537537
Py_ssize_t pos
538+
str typ
538539

539540
assert obj.tzinfo is None
540541

@@ -646,7 +647,7 @@ cdef inline int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz,
646647
if not is_tzlocal(tz):
647648
# get_dst_info cannot extract offsets from tzlocal because its
648649
# dependent on a datetime
649-
trans, deltas, typ = get_dst_info(tz)
650+
trans, deltas, _ = get_dst_info(tz)
650651
if not to_utc:
651652
# We add `offset` below instead of subtracting it
652653
deltas = -1 * np.array(deltas, dtype='i8')
@@ -690,7 +691,7 @@ cdef inline int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz,
690691
"""
691692
cdef:
692693
npy_datetimestruct dts
693-
int64_t result, delta
694+
int64_t delta
694695
datetime dt
695696

696697
dt64_to_dtstruct(val, &dts)
@@ -879,18 +880,20 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
879880
localized : ndarray[int64_t]
880881
"""
881882
cdef:
882-
ndarray[int64_t] trans
883883
int64_t[:] deltas, idx_shifted, idx_shifted_left, idx_shifted_right
884-
ndarray ambiguous_array
884+
ndarray[uint8_t, cast=True] ambiguous_array, both_nat, both_eq
885885
Py_ssize_t i, idx, pos, ntrans, n = len(vals)
886886
Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right
887887
int64_t *tdata
888888
int64_t v, left, right, val, v_left, v_right, new_local, remaining_mins
889889
int64_t HOURS_NS = HOUR_SECONDS * 1000000000
890-
ndarray[int64_t] result, result_a, result_b, dst_hours
890+
ndarray[int64_t] trans, result, result_a, result_b, dst_hours
891+
ndarray[int64_t] trans_idx, grp, delta, a_idx, b_idx, one_diff
891892
npy_datetimestruct dts
892893
bint infer_dst = False, is_dst = False, fill = False
893894
bint shift = False, fill_nonexist = False
895+
list trans_grp
896+
str stamp
894897

895898
# Vectorized version of DstTzInfo.localize
896899
if is_utc(tz) or tz is None:
@@ -923,7 +926,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
923926
if len(ambiguous) != len(vals):
924927
raise ValueError("Length of ambiguous bool-array must be "
925928
"the same size as vals")
926-
ambiguous_array = np.asarray(ambiguous)
929+
ambiguous_array = np.asarray(ambiguous, dtype=bool)
927930

928931
if nonexistent == 'NaT':
929932
fill_nonexist = True
@@ -933,7 +936,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
933936
assert nonexistent in ('raise', None), ("nonexistent must be one of"
934937
" {'NaT', 'raise', 'shift'}")
935938

936-
trans, deltas, typ = get_dst_info(tz)
939+
trans, deltas, _ = get_dst_info(tz)
937940

938941
tdata = <int64_t*>cnp.PyArray_DATA(trans)
939942
ntrans = len(trans)
@@ -984,7 +987,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
984987
# years which is useful for checking that there is not an ambiguous
985988
# transition in an individual year.
986989
if trans_idx.size > 0:
987-
one_diff = np.where(np.diff(trans_idx) != 1)[0] +1
990+
one_diff = np.where(np.diff(trans_idx) != 1)[0] + 1
988991
trans_grp = np.array_split(trans_idx, one_diff)
989992

990993
# Iterate through each day, if there are no hours where the
@@ -1172,13 +1175,14 @@ cdef int64_t[:] _normalize_local(int64_t[:] stamps, tzinfo tz):
11721175
result : int64 ndarray of converted of normalized nanosecond timestamps
11731176
"""
11741177
cdef:
1175-
Py_ssize_t n = len(stamps)
1178+
Py_ssize_t i, n = len(stamps)
11761179
int64_t[:] result = np.empty(n, dtype=np.int64)
11771180
ndarray[int64_t] trans
11781181
int64_t[:] deltas
1182+
str typ
11791183
Py_ssize_t[:] pos
11801184
npy_datetimestruct dts
1181-
int64_t delta
1185+
int64_t delta, local_val
11821186

11831187
if is_utc(tz):
11841188
with nogil:
@@ -1264,6 +1268,7 @@ def is_date_array_normalized(int64_t[:] stamps, object tz=None):
12641268
int64_t[:] deltas
12651269
npy_datetimestruct dts
12661270
int64_t local_val, delta
1271+
str typ
12671272

12681273
if tz is None or is_utc(tz):
12691274
for i in range(n):

0 commit comments

Comments
 (0)