From d266f7308059850ee44b522e5e348d88ce633bbd Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 13 Oct 2019 20:15:38 -0700 Subject: [PATCH 1/4] CLN: Exception in _libs --- pandas/_libs/lib.pyx | 5 +++-- pandas/_libs/tslibs/parsing.pyx | 2 +- pandas/_libs/tslibs/timezones.pyx | 7 ++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 1c2f80b832201..06e331304e1f5 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2066,7 +2066,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, floats[i] = float(val) complexes[i] = complex(val) seen.float_ = 1 - except Exception: + except ValueError: seen.object_ = 1 break else: @@ -2346,7 +2346,8 @@ def to_object_array_tuples(rows: object): row = rows[i] for j in range(len(row)): result[i, j] = row[j] - except Exception: + except TypeError: + # e.g. "Expected tuple, got list" # upcast any subclasses to tuple for i in range(n): row = (rows[i],) if checknull(rows[i]) else tuple(rows[i]) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 33665484311ba..bf0a0ae5a3fe9 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -581,7 +581,7 @@ def try_parse_dates(object[:] values, parser=None, else: result[i] = parse_date(values[i]) except Exception: - # failed + # Since parser is user-defined, we can't guess what it migh raise return values else: parse_date = parser diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index cbfbc14c35b35..bc1fdfae99de9 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -226,11 +226,8 @@ cdef object get_dst_info(object tz): if treat_tz_as_pytz(tz): trans = np.array(tz._utc_transition_times, dtype='M8[ns]') trans = trans.view('i8') - try: - if tz._utc_transition_times[0].year == 1: - trans[0] = NPY_NAT + 1 - except Exception: - pass + if tz._utc_transition_times[0].year == 1: + trans[0] = NPY_NAT + 1 deltas = unbox_utcoffsets(tz._transition_info) typ = 'pytz' From ecba7635ac15df04aac5c7e2a9c79fbf3f3f8818 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 13 Oct 2019 20:35:57 -0700 Subject: [PATCH 2/4] suppress some warnings --- pandas/_libs/intervaltree.pxi.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/intervaltree.pxi.in b/pandas/_libs/intervaltree.pxi.in index ac713a928973f..8bf1532a3199b 100644 --- a/pandas/_libs/intervaltree.pxi.in +++ b/pandas/_libs/intervaltree.pxi.in @@ -3,7 +3,6 @@ Template for intervaltree WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in """ - from pandas._libs.algos import is_monotonic ctypedef fused scalar_t: @@ -158,7 +157,7 @@ cdef class IntervalTree(IntervalMixin): # TODO: write get_indexer_intervals cdef: - size_t old_len + Py_ssize_t old_len Py_ssize_t i Int64Vector result @@ -179,7 +178,7 @@ cdef class IntervalTree(IntervalMixin): the given array of scalar targets. Non-unique positions are repeated. """ cdef: - size_t old_len + Py_ssize_t old_len Py_ssize_t i Int64Vector result, missing From 326ddfbe0c021356eca43f2b6d1a947fea1a6488 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 13 Oct 2019 20:38:13 -0700 Subject: [PATCH 3/4] restore whitespace --- pandas/_libs/intervaltree.pxi.in | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/intervaltree.pxi.in b/pandas/_libs/intervaltree.pxi.in index 8bf1532a3199b..08bfaf21db9fb 100644 --- a/pandas/_libs/intervaltree.pxi.in +++ b/pandas/_libs/intervaltree.pxi.in @@ -3,6 +3,7 @@ Template for intervaltree WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in """ + from pandas._libs.algos import is_monotonic ctypedef fused scalar_t: From 7ee9d8b16e73a43e3e2f6f034dd4674e1e6d4486 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 14 Oct 2019 07:40:07 -0700 Subject: [PATCH 4/4] catch TypeError --- pandas/_libs/lib.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 06e331304e1f5..36dddbb446e83 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2066,7 +2066,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, floats[i] = float(val) complexes[i] = complex(val) seen.float_ = 1 - except ValueError: + except (ValueError, TypeError): seen.object_ = 1 break else: