Skip to content

CLN: handle bare exceptions im timedeltas, timestamps, reduction #28346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ def apply_frame_axis0(object frame, object f, object names,

try:
piece = f(chunk)
except:
except Exception:
# We can't be more specific without knowing something about `f`
raise InvalidApply('Let this error raise above us')

# Need to infer if low level index slider will cause segfaults
Expand All @@ -539,6 +540,7 @@ def apply_frame_axis0(object frame, object f, object names,
else:
mutated = True
except AttributeError:
# `piece` might not have an index, could be e.g. an int
pass

results.append(piece)
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/c_timestamp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ cdef class _Timestamp(datetime):

try:
stamp += zone.strftime(' %%Z')
except:
except AttributeError:
# e.g. tzlocal has no `strftime`
pass

tz = ", tz='{0}'".format(zone) if zone is not None else ""
Expand Down
11 changes: 8 additions & 3 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,13 @@ def array_to_timedelta64(object[:] values, unit='ns', errors='raise'):
# this is where all of the error handling will take place.
try:
for i in range(n):
result[i] = parse_timedelta_string(values[i])
except:
if values[i] is NaT:
# we allow this check in the fast-path because NaT is a C-object
# so this is an inexpensive check
iresult[i] = NPY_NAT
else:
result[i] = parse_timedelta_string(values[i])
except (TypeError, ValueError):
unit = parse_timedelta_unit(unit)
for i in range(n):
try:
Expand Down Expand Up @@ -309,7 +314,7 @@ cdef inline int64_t cast_from_unit(object ts, object unit) except? -1:
return <int64_t>(base * m) + <int64_t>(frac * m)


cdef inline parse_timedelta_string(object ts):
cdef inline int64_t parse_timedelta_string(str ts) except? -1:
"""
Parse a regular format timedelta string. Return an int64_t (in ns)
or raise a ValueError on an invalid parse.
Expand Down