Skip to content

Commit 8f20e82

Browse files
authored
CLN: Clean up some iteration logic in tslib (pandas-dev#55320)
1 parent 69b5d5a commit 8f20e82

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

pandas/_libs/tslib.pyx

+3-7
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,18 @@ cpdef array_to_datetime(
455455
set out_tzoffset_vals = set()
456456
tzinfo tz_out = None
457457
bint found_tz = False, found_naive = False
458-
cnp.broadcast mi
458+
cnp.flatiter it = cnp.PyArray_IterNew(values)
459459

460460
# specify error conditions
461461
assert is_raise or is_ignore or is_coerce
462462

463463
result = np.empty((<object>values).shape, dtype="M8[ns]")
464-
mi = cnp.PyArray_MultiIterNew2(result, values)
465464
iresult = result.view("i8").ravel()
466465

467466
for i in range(n):
468467
# Analogous to `val = values[i]`
469-
val = <object>(<PyObject**>cnp.PyArray_MultiIter_DATA(mi, 1))[0]
468+
val = cnp.PyArray_GETITEM(values, cnp.PyArray_ITER_DATA(it))
469+
cnp.PyArray_ITER_NEXT(it)
470470

471471
try:
472472
if checknull_with_nat_and_na(val):
@@ -511,7 +511,6 @@ cpdef array_to_datetime(
511511
if parse_today_now(val, &iresult[i], utc):
512512
# We can't _quite_ dispatch this to convert_str_to_tsobject
513513
# bc there isn't a nice way to pass "utc"
514-
cnp.PyArray_MultiIter_NEXT(mi)
515514
continue
516515

517516
_ts = convert_str_to_tsobject(
@@ -540,13 +539,10 @@ cpdef array_to_datetime(
540539
else:
541540
raise TypeError(f"{type(val)} is not convertible to datetime")
542541

543-
cnp.PyArray_MultiIter_NEXT(mi)
544-
545542
except (TypeError, OverflowError, ValueError) as ex:
546543
ex.args = (f"{ex}, at position {i}",)
547544
if is_coerce:
548545
iresult[i] = NPY_NAT
549-
cnp.PyArray_MultiIter_NEXT(mi)
550546
continue
551547
elif is_raise:
552548
raise

0 commit comments

Comments
 (0)