diff --git a/ci/fix_wheels.py b/ci/fix_wheels.py index 525aacf572cd4..c8df5a690aad1 100644 --- a/ci/fix_wheels.py +++ b/ci/fix_wheels.py @@ -48,7 +48,7 @@ os.path.join(base_redist_dir, "vcruntime140_1.dll"), "pandas/_libs/window/vcruntime140_1.dll", ) - except Exception as e: + except Exception as e: # pylint: disable=broad-except success = False exception = e diff --git a/doc/make.py b/doc/make.py index f5bf170c6274d..9f6d15dc83f0d 100755 --- a/doc/make.py +++ b/doc/make.py @@ -203,7 +203,7 @@ def _add_redirects(self): try: title = self._get_page_title(row[1]) - except Exception: + except Exception: # pylint: disable=broad-except # the file can be an ipynb and not an rst, or docutils # may not be able to read the rst because it has some # sphinx specific stuff diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 6d9f5510eb8c5..a2fb3935c06e9 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -281,7 +281,7 @@ def transform_str_or_callable(self, func) -> DataFrame | Series: # Two possible ways to use a UDF - apply or call directly try: return obj.apply(func, args=args, **kwargs) - except Exception: + except Exception: # pylint: disable=broad-except return func(obj, *args, **kwargs) def agg_list_like(self) -> DataFrame | Series: @@ -706,7 +706,7 @@ def apply_empty_result(self): r = self.f(Series([], dtype=np.float64)) else: r = self.f(Series(index=self.columns, dtype=np.float64)) - except Exception: + except Exception: # pylint: disable=broad-except pass else: should_reduce = not isinstance(r, Series) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index a9ef1fca7e8e7..511553b711979 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1464,7 +1464,7 @@ def _choose_path(self, fast_path: Callable, slow_path: Callable, group: DataFram res_fast = fast_path(group) except AssertionError: raise # pragma: no cover - except Exception: + except Exception: # pylint: disable=broad-except # GH#29631 For user-defined function, we can't predict what may be # raised; see test_transform.test_transform_fastpath_raises return path, res diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 81d502b60d609..9edbcff77cd1b 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -167,7 +167,7 @@ def map(self, mapper, na_action=None): if not isinstance(result, Index): raise TypeError("The map function must return an Index object") return result - except Exception: + except Exception: # pylint: disable=broad-except return self.astype(object).map(mapper) @cache_readonly diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index b0f3754271894..b356d6322c0d3 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -1134,7 +1134,7 @@ def converter(*date_cols): if isinstance(result, datetime.datetime): raise Exception("scalar parser") return result - except Exception: + except Exception: # pylint: disable=broad-except return tools.to_datetime( parsing.try_parse_dates( parsing.concat_date_cols(date_cols), diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 8246d3a7e5c96..75bfd31f61618 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1160,7 +1160,7 @@ def remove(self, key: str, where=None, start=None, stop=None) -> None: except AssertionError: # surface any assertion errors for e.g. debugging raise - except Exception as err: + except Exception as err: # pylint: disable=broad-except # In tests we get here with ClosedFileError, TypeError, and # _table_mod.NoSuchNodeError. TODO: Catch only these? @@ -1601,7 +1601,7 @@ def info(self) -> str: except AssertionError: # surface any assertion errors for e.g. debugging raise - except Exception as detail: + except Exception as detail: # pylint: disable=broad-except keys.append(k) dstr = pprint_thing(detail) values.append(f"[invalid_HDFStore node: {dstr}]") diff --git a/pandas/io/sql.py b/pandas/io/sql.py index e3510f71bd0cd..1bd964ae93b91 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -575,7 +575,7 @@ def read_sql( try: _is_table_name = pandas_sql.has_table(sql) - except Exception: + except Exception: # pylint: disable=broad-except # using generic exception to catch errors from sql drivers (GH24988) _is_table_name = False diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index 69f46a333503d..2fb615c53729f 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -290,7 +290,7 @@ def _convert_1d(values, unit, axis): def try_parse(values): try: return mdates.date2num(tools.to_datetime(values)) - except Exception: + except Exception: # pylint: disable=broad-except return values if isinstance(values, (datetime, pydt.date, np.datetime64, pydt.time)): @@ -314,7 +314,7 @@ def try_parse(values): try: values = tools.to_datetime(values) - except Exception: + except Exception: # pylint: disable=broad-except pass values = mdates.date2num(values) @@ -427,6 +427,7 @@ def __call__(self): if len(all_dates) > 0: locs = self.raise_if_exceeds(mdates.date2num(all_dates)) return locs + # pylint: disable-next=broad-except except Exception: # pragma: no cover pass diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 664e8dfdb4d20..13e6523d572c2 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1479,7 +1479,7 @@ def get_label(i): i = int(i) try: return pprint_thing(data.index[i]) - except Exception: + except Exception: # pylint: disable=broad-except return "" if self._need_to_set_index: diff --git a/pandas/tests/extension/base/dim2.py b/pandas/tests/extension/base/dim2.py index 210e566c7e463..da32c62d74747 100644 --- a/pandas/tests/extension/base/dim2.py +++ b/pandas/tests/extension/base/dim2.py @@ -173,12 +173,12 @@ def test_reductions_2d_axis_none(self, data, method): err_result = None try: expected = getattr(data, method)() - except Exception as err: + except Exception as err: # pylint: disable=broad-except # if the 1D reduction is invalid, the 2D reduction should be as well err_expected = err try: result = getattr(arr2d, method)(axis=None) - except Exception as err2: + except Exception as err2: # pylint: disable=broad-except err_result = err2 else: @@ -206,10 +206,10 @@ def test_reductions_2d_axis0(self, data, method): result = getattr(arr2d, method)(axis=0, **kwargs) else: result = getattr(arr2d, method)(axis=0, **kwargs) - except Exception as err: + except Exception as err: # pylint: disable=broad-except try: getattr(data, method)() - except Exception as err2: + except Exception as err2: # pylint: disable=broad-except assert type(err) == type(err2) return else: @@ -255,10 +255,10 @@ def test_reductions_2d_axis1(self, data, method): try: result = getattr(arr2d, method)(axis=1) - except Exception as err: + except Exception as err: # pylint: disable=broad-except try: getattr(data, method)() - except Exception as err2: + except Exception as err2: # pylint: disable=broad-except assert type(err) == type(err2) return else: diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 2df410dff2b00..1e1e9f3dbba2c 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -346,7 +346,7 @@ def test_diff(self, data, periods): try: # does this array implement ops? op(data, data) - except Exception: + except Exception: # pylint: disable=broad-except pytest.skip(f"{type(data)} does not support diff") s = pd.Series(data) result = s.diff(periods) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 419d1e114bade..d56f590728673 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -147,7 +147,7 @@ def _compare_other(self, ser: pd.Series, data, op, other): exc = None try: result = op(ser, other) - except Exception as err: + except Exception as err: # pylint: disable=broad-except exc = err if exc is None: @@ -206,7 +206,7 @@ def test_unary_ufunc_dunder_equivalence(self, data, ufunc): exc = None try: result = getattr(data, attr)() - except Exception as err: + except Exception as err: # pylint: disable=broad-except exc = err # if __pos__ raised, then so should the ufunc diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index ef5060265a0b4..5046932cab228 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -1257,7 +1257,7 @@ def test_compare_array(self, data, comparison_op, na_value, request): exc = None try: result = comparison_op(ser, other) - except Exception as err: + except Exception as err: # pylint: disable=broad-except exc = err if exc is None: diff --git a/pandas/tests/io/conftest.py b/pandas/tests/io/conftest.py index 2fac7ca0b3e00..3a34d2cf82a9d 100644 --- a/pandas/tests/io/conftest.py +++ b/pandas/tests/io/conftest.py @@ -106,7 +106,7 @@ def s3_base(worker_id): r = requests.get(endpoint_uri) if r.ok: break - except Exception: + except Exception: # pylint: disable=broad-except pass timeout -= 0.1 time.sleep(0.1) @@ -154,12 +154,12 @@ def add_tips_files(bucket_name): try: cli.create_bucket(Bucket=bucket) - except Exception: + except Exception: # pylint: disable=broad-except # OK is bucket already exists pass try: cli.create_bucket(Bucket="cant_get_it", ACL="private") - except Exception: + except Exception: # pylint: disable=broad-except # OK is bucket already exists pass timeout = 2 @@ -176,11 +176,11 @@ def add_tips_files(bucket_name): try: s3.rm(bucket, recursive=True) - except Exception: + except Exception: # pylint: disable=broad-except pass try: s3.rm("cant_get_it", recursive=True) - except Exception: + except Exception: # pylint: disable=broad-except pass timeout = 2 while cli.list_buckets()["Buckets"] and timeout > 0: diff --git a/pandas/tests/io/parser/test_c_parser_only.py b/pandas/tests/io/parser/test_c_parser_only.py index ec08fb0d60648..ec8b0175d9a20 100644 --- a/pandas/tests/io/parser/test_c_parser_only.py +++ b/pandas/tests/io/parser/test_c_parser_only.py @@ -68,7 +68,7 @@ def test_buffer_rd_bytes(c_parser_only): compression="gzip", delim_whitespace=True, ) - except Exception: + except Exception: # pylint: disable=broad-except pass diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index daa2dffeaa143..45995d1407a3a 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -1276,7 +1276,7 @@ class ErrorThread(threading.Thread): def run(self): try: super().run() - except Exception as err: + except Exception as err: # pylint: disable=broad-except self.err = err else: self.err = None diff --git a/pandas/tests/tslibs/test_conversion.py b/pandas/tests/tslibs/test_conversion.py index bf9a45c6d9d7a..72e09a9144128 100644 --- a/pandas/tests/tslibs/test_conversion.py +++ b/pandas/tests/tslibs/test_conversion.py @@ -37,12 +37,12 @@ def _compare_local_to_utc(tz_didx, naive_didx): try: result = tzconversion.tz_localize_to_utc(naive_didx.asi8, tz_didx.tz) err1 = None - except Exception as err: + except Exception as err: # pylint: disable=broad-except err1 = err try: expected = naive_didx.map(lambda x: x.tz_localize(tz_didx.tz)).asi8 - except Exception as err: + except Exception as err: # pylint: disable=broad-except err2 = err if err1 is not None: diff --git a/pyproject.toml b/pyproject.toml index 7b4c9425d557c..cb087b1c5cd9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,7 +130,6 @@ disable = [ "arguments-out-of-order", "arguments-renamed", "attribute-defined-outside-init", - "broad-except", "comparison-with-callable", "dangerous-default-value", "deprecated-module",