From c7786760a7aad378b7ed4119f1973e296327faaa Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 26 Sep 2019 16:47:27 -0700 Subject: [PATCH] CLN: Exception in io, plotting --- pandas/plotting/_matplotlib/tools.py | 13 +++++-------- pandas/tests/io/test_sql.py | 7 +++++-- pandas/tests/plotting/common.py | 12 ++++-------- pandas/tests/plotting/test_datetimelike.py | 9 +++------ 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 1c9bd01b16739..eddc9b4cd21bd 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -12,14 +12,11 @@ def format_date_labels(ax, rot): # mini version of autofmt_xdate - try: - for label in ax.get_xticklabels(): - label.set_ha("right") - label.set_rotation(rot) - fig = ax.get_figure() - fig.subplots_adjust(bottom=0.2) - except Exception: # pragma: no cover - pass + for label in ax.get_xticklabels(): + label.set_ha("right") + label.set_rotation(rot) + fig = ax.get_figure() + fig.subplots_adjust(bottom=0.2) def table(ax, data, rowLabels=None, colLabels=None, **kwargs): diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 89bc98b5a1006..7491cef17ebfc 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -539,13 +539,16 @@ def _transaction_test(self): with self.pandasSQL.run_transaction() as trans: trans.execute("CREATE TABLE test_trans (A INT, B TEXT)") + class DummyException(Exception): + pass + # Make sure when transaction is rolled back, no rows get inserted ins_sql = "INSERT INTO test_trans (A,B) VALUES (1, 'blah')" try: with self.pandasSQL.run_transaction() as trans: trans.execute(ins_sql) - raise Exception("error") - except Exception: + raise DummyException("error") + except DummyException: # ignore raised exception pass res = self.pandasSQL.read_query("SELECT * FROM test_trans") diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 5a591f72d7361..b7ecc6be43733 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -536,18 +536,14 @@ def _check_plot_works(f, filterwarnings="always", **kwargs): plt.clf() - ax = kwargs.get("ax", fig.add_subplot(211)) # noqa + kwargs.get("ax", fig.add_subplot(211)) ret = f(**kwargs) assert_is_valid_plot_return_object(ret) - try: - kwargs["ax"] = fig.add_subplot(212) - ret = f(**kwargs) - except Exception: - pass - else: - assert_is_valid_plot_return_object(ret) + kwargs["ax"] = fig.add_subplot(212) + ret = f(**kwargs) + assert_is_valid_plot_return_object(ret) with ensure_clean(return_filelike=True) as path: plt.savefig(path) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index e2b7f2819f957..be24f102851b7 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1553,12 +1553,9 @@ def _check_plot_works(f, freq=None, series=None, *args, **kwargs): assert ax.freq == freq ax = fig.add_subplot(212) - try: - kwargs["ax"] = ax - ret = f(*args, **kwargs) - assert ret is not None # do something more intelligent - except Exception: - pass + kwargs["ax"] = ax + ret = f(*args, **kwargs) + assert ret is not None # TODO: do something more intelligent with ensure_clean(return_filelike=True) as path: plt.savefig(path)