Skip to content

Commit

Permalink
CLN: Clean up some iteration logic in tslib (pandas-dev#55320)
Browse files Browse the repository at this point in the history
  • Loading branch information
lithomas1 authored Sep 29, 2023
1 parent 69b5d5a commit 8f20e82
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,18 @@ cpdef array_to_datetime(
set out_tzoffset_vals = set()
tzinfo tz_out = None
bint found_tz = False, found_naive = False
cnp.broadcast mi
cnp.flatiter it = cnp.PyArray_IterNew(values)

# specify error conditions
assert is_raise or is_ignore or is_coerce

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

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

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

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

cnp.PyArray_MultiIter_NEXT(mi)

except (TypeError, OverflowError, ValueError) as ex:
ex.args = (f"{ex}, at position {i}",)
if is_coerce:
iresult[i] = NPY_NAT
cnp.PyArray_MultiIter_NEXT(mi)
continue
elif is_raise:
raise
Expand Down

0 comments on commit 8f20e82

Please sign in to comment.