diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index c892c1cf1b8a3..bf940eb03e06f 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -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 @@ -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) diff --git a/pandas/_libs/tslibs/c_timestamp.pyx b/pandas/_libs/tslibs/c_timestamp.pyx index a45b8c9b35dfa..dfa66d7e2d862 100644 --- a/pandas/_libs/tslibs/c_timestamp.pyx +++ b/pandas/_libs/tslibs/c_timestamp.pyx @@ -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 "" diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index d24aafae0967d..ad7c32ca31940 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -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: @@ -309,7 +314,7 @@ cdef inline int64_t cast_from_unit(object ts, object unit) except? -1: return (base * m) + (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.