From bc5c6c44f9239382d559a1a5955f960a6398926a Mon Sep 17 00:00:00 2001 From: Dylan Brandt Date: Tue, 14 Jan 2020 19:45:06 -0600 Subject: [PATCH 1/3] Issue ##30999, Added match = msg as a second parameter in applicable lines. --- pandas/tests/io/test_html.py | 8 +-- pandas/tests/io/test_parquet.py | 4 +- pandas/tests/io/test_sql.py | 8 +-- pandas/tests/io/test_stata.py | 2 +- pandas/tests/plotting/test_backend.py | 2 +- pandas/tests/plotting/test_boxplot_method.py | 4 +- pandas/tests/plotting/test_frame.py | 54 ++++++++++---------- pandas/tests/plotting/test_hist_method.py | 20 ++++---- pandas/tests/plotting/test_series.py | 18 +++---- pandas/tests/reductions/test_reductions.py | 24 ++++----- 10 files changed, 72 insertions(+), 72 deletions(-) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 626df839363cb..164ca61a923e0 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -276,14 +276,14 @@ def test_file_like(self): @tm.network def test_bad_url_protocol(self): - with pytest.raises(URLError): + with pytest.raises(URLError, match=msg): self.read_html("git://github.com", match=".*Water.*") @tm.network @pytest.mark.slow def test_invalid_url(self): try: - with pytest.raises(URLError): + with pytest.raises(URLError, match=msg): self.read_html("http://www.a23950sdfa908sd.com", match=".*Water.*") except ValueError as e: assert "No tables found" in str(e) @@ -357,7 +357,7 @@ def test_regex_idempotency(self): def test_negative_skiprows(self): msg = r"\(you passed a negative value\)" - with pytest.raises(ValueError, match=msg): + with (ValueError, match=msg): self.read_html(self.spam_data, "Water", skiprows=-1) @tm.network @@ -964,7 +964,7 @@ def test_decimal_rows(self): def test_bool_header_arg(self): # GH 6114 for arg in [True, False]: - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): self.read_html(self.spam_data, header=arg) def test_converters(self): diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index d51c712ed5abd..e7575f206b24f 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -178,7 +178,7 @@ def compare(repeat): def test_invalid_engine(df_compat): - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): check_round_trip(df_compat, "foo", "bar") @@ -667,7 +667,7 @@ def test_error_on_using_partition_cols_and_partition_on(self, fp, df_full): # GH #23283 partition_cols = ["bool", "int"] df = df_full - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): with tm.ensure_clean_dir() as path: df.to_parquet( path, diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 45b3e839a08d1..11e46ef1261ef 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2417,7 +2417,7 @@ def test_execute_fail(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn) - with pytest.raises(Exception): + with pytest.raises(Exception, match=msg): sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn) def test_execute_closed_connection(self): @@ -2436,7 +2436,7 @@ def test_execute_closed_connection(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) self.conn.close() - with pytest.raises(Exception): + with pytest.raises(Exception, match=msg): tquery("select * from test", con=self.conn) def test_na_roundtrip(self): @@ -2700,7 +2700,7 @@ def test_execute_fail(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn) - with pytest.raises(Exception): + with pytest.raises(Exception, match=msg): sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn) def test_execute_closed_connection(self, request, datapath): @@ -2721,7 +2721,7 @@ def test_execute_closed_connection(self, request, datapath): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) self.conn.close() - with pytest.raises(Exception): + with pytest.raises(Exception, match=msg): tquery("select * from test", con=self.conn) # Initialize connection again (needed for tearDown) diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index edb766a67af89..a5a7333f4b232 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -1374,7 +1374,7 @@ def test_unsupported_datetype(self): "dates": dates, } ) - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): with tm.ensure_clean() as path: original.to_stata(path) diff --git a/pandas/tests/plotting/test_backend.py b/pandas/tests/plotting/test_backend.py index 9025f8c361a82..632530a7d84ad 100644 --- a/pandas/tests/plotting/test_backend.py +++ b/pandas/tests/plotting/test_backend.py @@ -92,7 +92,7 @@ def test_setting_backend_without_plot_raises(): @td.skip_if_mpl def test_no_matplotlib_ok(): - with pytest.raises(ImportError): + with pytest.raises(ImportError, match=msg): pandas.plotting._core._get_plot_backend("matplotlib") diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 8ee279f0e1f38..6686611b0a449 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -96,7 +96,7 @@ def test_boxplot_return_type_legacy(self): index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.boxplot(return_type="NOTATYPE") result = df.boxplot() @@ -429,7 +429,7 @@ def test_grouped_box_multiple_axes(self): tm.assert_numpy_array_equal(returned, axes[1]) assert returned[0].figure is fig - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required with tm.assert_produces_warning(UserWarning): diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 1c429bafa9a19..ede6ea730d0d3 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -187,7 +187,7 @@ def test_rgb_tuple_color(self): def test_color_empty_string(self): df = DataFrame(randn(10, 2)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(color="") def test_color_and_style_arguments(self): @@ -203,7 +203,7 @@ def test_color_and_style_arguments(self): assert color == ["red", "black"] # passing both 'color' and 'style' arguments should not be allowed # if there is a color symbol in the style strings: - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(color=["red", "black"], style=["k-", "r--"]) def test_nonnumeric_exclude(self): @@ -628,9 +628,9 @@ def test_subplots_layout(self): self._check_axes_shape(axes, axes_num=3, layout=(4, 1)) assert axes.shape == (4, 1) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(subplots=True, layout=(1, 1)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(subplots=True, layout=(-1, -1)) # single column @@ -673,7 +673,7 @@ def test_subplots_multiple_axes(self): self._check_axes_shape(axes, axes_num=6, layout=(2, 3)) tm.close() - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required df.plot(subplots=True, ax=axes) @@ -784,9 +784,9 @@ def test_negative_log(self): columns=["x", "y", "z", "four"], ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot.area(logy=True) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot.area(loglog=True) def _compare_stacked_y_cood(self, normal_lines, stacked_lines): @@ -826,7 +826,7 @@ def test_line_area_stacked(self): self._compare_stacked_y_cood(ax1.lines[2:], ax2.lines[2:]) _check_plot_works(mixed_df.plot, stacked=False) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): mixed_df.plot(stacked=True) # Use an index with strictly positive values, preventing @@ -1153,9 +1153,9 @@ def test_plot_scatter(self): _check_plot_works(df.plot.scatter, x="x", y="y") _check_plot_works(df.plot.scatter, x=1, y=2) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot.scatter(x="x") - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot.scatter(y="y") # GH 6951 @@ -1310,7 +1310,7 @@ def test_plot_scatter_with_c(self): def test_scatter_colors(self): df = DataFrame({"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3]}) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot.scatter(x="a", y="b", c="c", color="green") default_colors = self._unpack_cycler(self.plt.rcParams) @@ -1580,7 +1580,7 @@ def test_boxplot_return_type(self): index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot.box(return_type="NOTATYPE") result = df.plot.box(return_type="dict") @@ -2036,7 +2036,7 @@ def test_line_colors(self): self._check_colors(ax.get_lines(), linecolors=custom_colors) tm.close() - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): # Color contains shorthand hex value results in ValueError custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"] # Forced show plot @@ -2093,7 +2093,7 @@ def test_line_colors_and_styles_subplots(self): self._check_colors(ax.get_lines(), linecolors=[c]) tm.close() - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): # Color contains shorthand hex value results in ValueError custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"] # Forced show plot @@ -2348,7 +2348,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): bp = df.plot.box(color=(0, 1, 0), sym="#123456", return_type="dict") _check_colors(bp, (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), "#123456") - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): # Color contains invalid key results in ValueError df.plot.box(color=dict(boxes="red", xxxx="blue")) @@ -2413,12 +2413,12 @@ def test_partially_invalid_plot_data(self): df = DataFrame(rand(10, 2), dtype=object) df[np.random.rand(df.shape[0]) > 0.5] = "a" for kind in kinds: - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot(kind=kind) def test_invalid_kind(self): df = DataFrame(randn(10, 2)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(kind="aasdf") @pytest.mark.parametrize( @@ -2432,14 +2432,14 @@ def test_invalid_kind(self): def test_invalid_xy_args(self, x, y, lbl): # GH 18671, 19699 allows y to be list-like but not x df = DataFrame({"A": [1, 2], "B": [3, 4], "C": [5, 6]}) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(x=x, y=y, label=lbl) @pytest.mark.parametrize("x,y", [("A", "B"), (["A"], "B")]) def test_invalid_xy_args_dup_cols(self, x, y): # GH 18671, 19699 allows y to be list-like but not x df = DataFrame([[1, 3, 5], [2, 4, 6]], columns=list("AAB")) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(x=x, y=y) @pytest.mark.parametrize( @@ -2518,7 +2518,7 @@ def test_allow_cmap(self): ax = df.plot.hexbin(x="A", y="B", cmap="YlGn") assert ax.collections[0].cmap.name == "YlGn" - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot.hexbin(x="A", y="B", cmap="YlGn", colormap="BuGn") @pytest.mark.slow @@ -2528,7 +2528,7 @@ def test_pie_df(self): columns=["X", "Y", "Z"], index=["a", "b", "c", "d", "e"], ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot.pie() ax = _check_plot_works(df.plot.pie, y="Y") @@ -2635,11 +2635,11 @@ def test_errorbar_plot(self): ax = _check_plot_works(s_df.plot, y="y", x="x", yerr=yerr) self._check_has_errorbars(ax, xerr=0, yerr=1) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(yerr=np.random.randn(11)) df_err = DataFrame({"x": ["zzz"] * 12, "y": ["zzz"] * 12}) - with pytest.raises((ValueError, TypeError)): + with pytest.raises((ValueError, TypeError), match=msg): df.plot(yerr=df_err) @pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError) @@ -2731,7 +2731,7 @@ def test_errorbar_asymmetrical(self): expected_0_0 = err[0, :, 0] * np.array([-1, 1]) tm.assert_almost_equal(yerr_0_0, expected_0_0) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(yerr=err.T) tm.close() @@ -2923,7 +2923,7 @@ def test_memory_leak(self): gc.collect() for key in results: # check that every plot was collected - with pytest.raises(ReferenceError): + with pytest.raises(ReferenceError, match=msg): # need to actually access something to get an error results[key].lines @@ -3102,7 +3102,7 @@ def test_df_grid_settings(self): def test_invalid_colormap(self): df = DataFrame(randn(3, 2), columns=["A", "B"]) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.plot(colormap="invalid_colormap") def test_plain_axes(self): @@ -3268,7 +3268,7 @@ def test_plot_no_rows(self): def test_plot_no_numeric_data(self): df = pd.DataFrame(["a", "b", "c"]) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot() def test_missing_markers_legend(self): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 50ebbc22f2739..c7702c017a17c 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -45,7 +45,7 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, figure=fig, ax=ax1) _check_plot_works(self.ts.hist, figure=fig, ax=ax2) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): self.ts.hist(by=self.ts.index, figure=fig) @pytest.mark.slow @@ -57,10 +57,10 @@ def test_hist_bins_legacy(self): @pytest.mark.slow def test_hist_layout(self): df = self.hist_df - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.height.hist(layout=(1, 1)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.height.hist(layout=[1, 1]) @pytest.mark.slow @@ -128,7 +128,7 @@ def test_plot_fails_when_ax_differs_from_figure(self): fig1 = figure() fig2 = figure() ax1 = fig1.add_subplot(111) - with pytest.raises(AssertionError): + with pytest.raises(AssertionError, match=msg): self.ts.hist(ax=ax1, figure=fig2) @@ -200,7 +200,7 @@ def test_hist_df_legacy(self): tm.close() # propagate attr exception from matplotlib.Axes.hist - with pytest.raises(AttributeError): + with pytest.raises(AttributeError, match=msg): ser.hist(foo="bar") @pytest.mark.slow @@ -235,13 +235,13 @@ def test_hist_layout(self): self._check_axes_shape(axes, axes_num=3, layout=expected) # layout too small for all 4 plots - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.hist(layout=(1, 1)) # invalid format for layout - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.hist(layout=(1,)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.hist(layout=(-1, -1)) @pytest.mark.slow @@ -328,7 +328,7 @@ def test_grouped_hist_legacy(self): tm.close() # propagate attr exception from matplotlib.Axes.hist - with pytest.raises(AttributeError): + with pytest.raises(AttributeError, match=msg): _grouped_hist(df.A, by=df.C, foo="bar") msg = "Specify figure size by tuple instead" @@ -419,7 +419,7 @@ def test_grouped_hist_multiple_axes(self): tm.assert_numpy_array_equal(returned, axes[1]) assert returned[0].figure is fig - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required axes = df.hist(column="height", ax=axes) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 8463f30bee8f0..d49c8b74b0063 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -337,7 +337,7 @@ def test_pie_series(self): assert t.get_fontsize() == 7 # includes negative value - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): series = Series([1, 2, 0, 4, -1], index=["a", "b", "c", "d", "e"]) series.plot.pie() @@ -396,7 +396,7 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, figure=fig, ax=ax1) _check_plot_works(self.ts.hist, figure=fig, ax=ax2) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): self.ts.hist(by=self.ts.index, figure=fig) @pytest.mark.slow @@ -408,10 +408,10 @@ def test_hist_bins_legacy(self): @pytest.mark.slow def test_hist_layout(self): df = self.hist_df - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.height.hist(layout=(1, 1)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.height.hist(layout=[1, 1]) @pytest.mark.slow @@ -586,7 +586,7 @@ def test_secondary_logy(self, input_logy, expected_scale): @pytest.mark.slow def test_plot_fails_with_dupe_color_and_style(self): x = Series(randn(2)) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): _, ax = self.plt.subplots() x.plot(style="k--", color="k", ax=ax) @@ -719,7 +719,7 @@ def test_partially_invalid_plot_data(self): def test_invalid_kind(self): s = Series([1, 2]) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): s.plot(kind="aasdf") @pytest.mark.slow @@ -766,11 +766,11 @@ def test_errorbar_plot(self): self._check_has_errorbars(ax, xerr=0, yerr=1) # check incorrect lengths and types - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): s.plot(yerr=np.arange(11)) s_err = ["zzz"] * 10 - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): s.plot(yerr=s_err) def test_table(self): @@ -929,7 +929,7 @@ def test_plot_no_rows(self): def test_plot_no_numeric_data(self): df = pd.Series(["a", "b", "c"]) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): df.plot() def test_style_single_ok(self): diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 7400b049961d5..924c1edf16a47 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -489,9 +489,9 @@ def test_numpy_minmax_period(self): def test_min_max_categorical(self): ci = pd.CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): ci.min() - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): ci.max() ci = pd.CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=True) @@ -830,15 +830,15 @@ def test_all_any_params(self): tm.assert_series_equal(s.any(level=0), Series([False, True, True])) # bool_only is not implemented with level option. - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): s.any(bool_only=True, level=0) - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): s.all(bool_only=True, level=0) # bool_only is not implemented alone. - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): s.any(bool_only=True) - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): s.all(bool_only=True) def test_timedelta64_analytics(self): @@ -900,13 +900,13 @@ def test_assert_idxminmax_raises(self, test_input, error_type): """ Cases where ``Series.argmax`` and related should raise an exception """ - with pytest.raises(error_type): + with pytest.raises(error_type, match=msg): test_input.idxmin() - with pytest.raises(error_type): + with pytest.raises(error_type, match=msg): test_input.idxmin(skipna=False) - with pytest.raises(error_type): + with pytest.raises(error_type, match=msg): test_input.idxmax() - with pytest.raises(error_type): + with pytest.raises(error_type, match=msg): test_input.idxmax(skipna=False) def test_idxminmax_with_inf(self): @@ -1001,9 +1001,9 @@ class TestCategoricalSeriesReductions: def test_min_max(self): # unordered cats have no min/max cat = Series(Categorical(["a", "b", "c", "d"], ordered=False)) - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): cat.min() - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): cat.max() cat = Series(Categorical(["a", "b", "c", "d"], ordered=True)) From 11433609d66260dc0eb109a0dbc952fa8ba90a1b Mon Sep 17 00:00:00 2001 From: Dylan Brandt Date: Tue, 14 Jan 2020 19:48:37 -0600 Subject: [PATCH 2/3] Fixed typo --- pandas/tests/io/test_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 164ca61a923e0..149151a3db25f 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -357,7 +357,7 @@ def test_regex_idempotency(self): def test_negative_skiprows(self): msg = r"\(you passed a negative value\)" - with (ValueError, match=msg): + with pytest.raises(ValueError, match=msg): self.read_html(self.spam_data, "Water", skiprows=-1) @tm.network From c2071681b755762e411d40a4f0baf6b212078d9c Mon Sep 17 00:00:00 2001 From: Dylan Brandt Date: Tue, 14 Jan 2020 21:01:57 -0600 Subject: [PATCH 3/3] Removed entry when msg is not defined --- pandas/tests/io/test_html.py | 6 +-- pandas/tests/io/test_parquet.py | 4 +- pandas/tests/io/test_sql.py | 8 +-- pandas/tests/plotting/test_backend.py | 2 +- pandas/tests/plotting/test_boxplot_method.py | 4 +- pandas/tests/plotting/test_frame.py | 52 ++++++++++---------- pandas/tests/plotting/test_hist_method.py | 20 ++++---- pandas/tests/plotting/test_series.py | 18 +++---- pandas/tests/reductions/test_reductions.py | 24 ++++----- 9 files changed, 69 insertions(+), 69 deletions(-) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 149151a3db25f..626df839363cb 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -276,14 +276,14 @@ def test_file_like(self): @tm.network def test_bad_url_protocol(self): - with pytest.raises(URLError, match=msg): + with pytest.raises(URLError): self.read_html("git://github.com", match=".*Water.*") @tm.network @pytest.mark.slow def test_invalid_url(self): try: - with pytest.raises(URLError, match=msg): + with pytest.raises(URLError): self.read_html("http://www.a23950sdfa908sd.com", match=".*Water.*") except ValueError as e: assert "No tables found" in str(e) @@ -964,7 +964,7 @@ def test_decimal_rows(self): def test_bool_header_arg(self): # GH 6114 for arg in [True, False]: - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): self.read_html(self.spam_data, header=arg) def test_converters(self): diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index e7575f206b24f..d51c712ed5abd 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -178,7 +178,7 @@ def compare(repeat): def test_invalid_engine(df_compat): - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): check_round_trip(df_compat, "foo", "bar") @@ -667,7 +667,7 @@ def test_error_on_using_partition_cols_and_partition_on(self, fp, df_full): # GH #23283 partition_cols = ["bool", "int"] df = df_full - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): with tm.ensure_clean_dir() as path: df.to_parquet( path, diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 11e46ef1261ef..45b3e839a08d1 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2417,7 +2417,7 @@ def test_execute_fail(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn) - with pytest.raises(Exception, match=msg): + with pytest.raises(Exception): sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn) def test_execute_closed_connection(self): @@ -2436,7 +2436,7 @@ def test_execute_closed_connection(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) self.conn.close() - with pytest.raises(Exception, match=msg): + with pytest.raises(Exception): tquery("select * from test", con=self.conn) def test_na_roundtrip(self): @@ -2700,7 +2700,7 @@ def test_execute_fail(self): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn) - with pytest.raises(Exception, match=msg): + with pytest.raises(Exception): sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn) def test_execute_closed_connection(self, request, datapath): @@ -2721,7 +2721,7 @@ def test_execute_closed_connection(self, request, datapath): sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn) self.conn.close() - with pytest.raises(Exception, match=msg): + with pytest.raises(Exception): tquery("select * from test", con=self.conn) # Initialize connection again (needed for tearDown) diff --git a/pandas/tests/plotting/test_backend.py b/pandas/tests/plotting/test_backend.py index 632530a7d84ad..9025f8c361a82 100644 --- a/pandas/tests/plotting/test_backend.py +++ b/pandas/tests/plotting/test_backend.py @@ -92,7 +92,7 @@ def test_setting_backend_without_plot_raises(): @td.skip_if_mpl def test_no_matplotlib_ok(): - with pytest.raises(ImportError, match=msg): + with pytest.raises(ImportError): pandas.plotting._core._get_plot_backend("matplotlib") diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 6686611b0a449..8ee279f0e1f38 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -96,7 +96,7 @@ def test_boxplot_return_type_legacy(self): index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.boxplot(return_type="NOTATYPE") result = df.boxplot() @@ -429,7 +429,7 @@ def test_grouped_box_multiple_axes(self): tm.assert_numpy_array_equal(returned, axes[1]) assert returned[0].figure is fig - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required with tm.assert_produces_warning(UserWarning): diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index ede6ea730d0d3..fe7941d21de4e 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -187,7 +187,7 @@ def test_rgb_tuple_color(self): def test_color_empty_string(self): df = DataFrame(randn(10, 2)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(color="") def test_color_and_style_arguments(self): @@ -203,7 +203,7 @@ def test_color_and_style_arguments(self): assert color == ["red", "black"] # passing both 'color' and 'style' arguments should not be allowed # if there is a color symbol in the style strings: - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(color=["red", "black"], style=["k-", "r--"]) def test_nonnumeric_exclude(self): @@ -628,9 +628,9 @@ def test_subplots_layout(self): self._check_axes_shape(axes, axes_num=3, layout=(4, 1)) assert axes.shape == (4, 1) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(subplots=True, layout=(1, 1)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(subplots=True, layout=(-1, -1)) # single column @@ -673,7 +673,7 @@ def test_subplots_multiple_axes(self): self._check_axes_shape(axes, axes_num=6, layout=(2, 3)) tm.close() - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required df.plot(subplots=True, ax=axes) @@ -784,9 +784,9 @@ def test_negative_log(self): columns=["x", "y", "z", "four"], ) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot.area(logy=True) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot.area(loglog=True) def _compare_stacked_y_cood(self, normal_lines, stacked_lines): @@ -826,7 +826,7 @@ def test_line_area_stacked(self): self._compare_stacked_y_cood(ax1.lines[2:], ax2.lines[2:]) _check_plot_works(mixed_df.plot, stacked=False) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): mixed_df.plot(stacked=True) # Use an index with strictly positive values, preventing @@ -1153,9 +1153,9 @@ def test_plot_scatter(self): _check_plot_works(df.plot.scatter, x="x", y="y") _check_plot_works(df.plot.scatter, x=1, y=2) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot.scatter(x="x") - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot.scatter(y="y") # GH 6951 @@ -1310,7 +1310,7 @@ def test_plot_scatter_with_c(self): def test_scatter_colors(self): df = DataFrame({"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3]}) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot.scatter(x="a", y="b", c="c", color="green") default_colors = self._unpack_cycler(self.plt.rcParams) @@ -1580,7 +1580,7 @@ def test_boxplot_return_type(self): index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot.box(return_type="NOTATYPE") result = df.plot.box(return_type="dict") @@ -2036,7 +2036,7 @@ def test_line_colors(self): self._check_colors(ax.get_lines(), linecolors=custom_colors) tm.close() - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): # Color contains shorthand hex value results in ValueError custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"] # Forced show plot @@ -2093,7 +2093,7 @@ def test_line_colors_and_styles_subplots(self): self._check_colors(ax.get_lines(), linecolors=[c]) tm.close() - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): # Color contains shorthand hex value results in ValueError custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"] # Forced show plot @@ -2348,7 +2348,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): bp = df.plot.box(color=(0, 1, 0), sym="#123456", return_type="dict") _check_colors(bp, (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), "#123456") - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): # Color contains invalid key results in ValueError df.plot.box(color=dict(boxes="red", xxxx="blue")) @@ -2418,7 +2418,7 @@ def test_partially_invalid_plot_data(self): def test_invalid_kind(self): df = DataFrame(randn(10, 2)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(kind="aasdf") @pytest.mark.parametrize( @@ -2432,14 +2432,14 @@ def test_invalid_kind(self): def test_invalid_xy_args(self, x, y, lbl): # GH 18671, 19699 allows y to be list-like but not x df = DataFrame({"A": [1, 2], "B": [3, 4], "C": [5, 6]}) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(x=x, y=y, label=lbl) @pytest.mark.parametrize("x,y", [("A", "B"), (["A"], "B")]) def test_invalid_xy_args_dup_cols(self, x, y): # GH 18671, 19699 allows y to be list-like but not x df = DataFrame([[1, 3, 5], [2, 4, 6]], columns=list("AAB")) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(x=x, y=y) @pytest.mark.parametrize( @@ -2518,7 +2518,7 @@ def test_allow_cmap(self): ax = df.plot.hexbin(x="A", y="B", cmap="YlGn") assert ax.collections[0].cmap.name == "YlGn" - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot.hexbin(x="A", y="B", cmap="YlGn", colormap="BuGn") @pytest.mark.slow @@ -2528,7 +2528,7 @@ def test_pie_df(self): columns=["X", "Y", "Z"], index=["a", "b", "c", "d", "e"], ) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot.pie() ax = _check_plot_works(df.plot.pie, y="Y") @@ -2635,11 +2635,11 @@ def test_errorbar_plot(self): ax = _check_plot_works(s_df.plot, y="y", x="x", yerr=yerr) self._check_has_errorbars(ax, xerr=0, yerr=1) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(yerr=np.random.randn(11)) df_err = DataFrame({"x": ["zzz"] * 12, "y": ["zzz"] * 12}) - with pytest.raises((ValueError, TypeError), match=msg): + with pytest.raises((ValueError, TypeError)): df.plot(yerr=df_err) @pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError) @@ -2731,7 +2731,7 @@ def test_errorbar_asymmetrical(self): expected_0_0 = err[0, :, 0] * np.array([-1, 1]) tm.assert_almost_equal(yerr_0_0, expected_0_0) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(yerr=err.T) tm.close() @@ -2923,7 +2923,7 @@ def test_memory_leak(self): gc.collect() for key in results: # check that every plot was collected - with pytest.raises(ReferenceError, match=msg): + with pytest.raises(ReferenceError): # need to actually access something to get an error results[key].lines @@ -3102,7 +3102,7 @@ def test_df_grid_settings(self): def test_invalid_colormap(self): df = DataFrame(randn(3, 2), columns=["A", "B"]) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.plot(colormap="invalid_colormap") def test_plain_axes(self): @@ -3268,7 +3268,7 @@ def test_plot_no_rows(self): def test_plot_no_numeric_data(self): df = pd.DataFrame(["a", "b", "c"]) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot() def test_missing_markers_legend(self): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index c7702c017a17c..50ebbc22f2739 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -45,7 +45,7 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, figure=fig, ax=ax1) _check_plot_works(self.ts.hist, figure=fig, ax=ax2) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): self.ts.hist(by=self.ts.index, figure=fig) @pytest.mark.slow @@ -57,10 +57,10 @@ def test_hist_bins_legacy(self): @pytest.mark.slow def test_hist_layout(self): df = self.hist_df - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.height.hist(layout=(1, 1)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.height.hist(layout=[1, 1]) @pytest.mark.slow @@ -128,7 +128,7 @@ def test_plot_fails_when_ax_differs_from_figure(self): fig1 = figure() fig2 = figure() ax1 = fig1.add_subplot(111) - with pytest.raises(AssertionError, match=msg): + with pytest.raises(AssertionError): self.ts.hist(ax=ax1, figure=fig2) @@ -200,7 +200,7 @@ def test_hist_df_legacy(self): tm.close() # propagate attr exception from matplotlib.Axes.hist - with pytest.raises(AttributeError, match=msg): + with pytest.raises(AttributeError): ser.hist(foo="bar") @pytest.mark.slow @@ -235,13 +235,13 @@ def test_hist_layout(self): self._check_axes_shape(axes, axes_num=3, layout=expected) # layout too small for all 4 plots - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.hist(layout=(1, 1)) # invalid format for layout - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.hist(layout=(1,)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.hist(layout=(-1, -1)) @pytest.mark.slow @@ -328,7 +328,7 @@ def test_grouped_hist_legacy(self): tm.close() # propagate attr exception from matplotlib.Axes.hist - with pytest.raises(AttributeError, match=msg): + with pytest.raises(AttributeError): _grouped_hist(df.A, by=df.C, foo="bar") msg = "Specify figure size by tuple instead" @@ -419,7 +419,7 @@ def test_grouped_hist_multiple_axes(self): tm.assert_numpy_array_equal(returned, axes[1]) assert returned[0].figure is fig - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required axes = df.hist(column="height", ax=axes) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index d49c8b74b0063..8463f30bee8f0 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -337,7 +337,7 @@ def test_pie_series(self): assert t.get_fontsize() == 7 # includes negative value - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): series = Series([1, 2, 0, 4, -1], index=["a", "b", "c", "d", "e"]) series.plot.pie() @@ -396,7 +396,7 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, figure=fig, ax=ax1) _check_plot_works(self.ts.hist, figure=fig, ax=ax2) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): self.ts.hist(by=self.ts.index, figure=fig) @pytest.mark.slow @@ -408,10 +408,10 @@ def test_hist_bins_legacy(self): @pytest.mark.slow def test_hist_layout(self): df = self.hist_df - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.height.hist(layout=(1, 1)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): df.height.hist(layout=[1, 1]) @pytest.mark.slow @@ -586,7 +586,7 @@ def test_secondary_logy(self, input_logy, expected_scale): @pytest.mark.slow def test_plot_fails_with_dupe_color_and_style(self): x = Series(randn(2)) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): _, ax = self.plt.subplots() x.plot(style="k--", color="k", ax=ax) @@ -719,7 +719,7 @@ def test_partially_invalid_plot_data(self): def test_invalid_kind(self): s = Series([1, 2]) - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): s.plot(kind="aasdf") @pytest.mark.slow @@ -766,11 +766,11 @@ def test_errorbar_plot(self): self._check_has_errorbars(ax, xerr=0, yerr=1) # check incorrect lengths and types - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError): s.plot(yerr=np.arange(11)) s_err = ["zzz"] * 10 - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): s.plot(yerr=s_err) def test_table(self): @@ -929,7 +929,7 @@ def test_plot_no_rows(self): def test_plot_no_numeric_data(self): df = pd.Series(["a", "b", "c"]) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): df.plot() def test_style_single_ok(self): diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 924c1edf16a47..7400b049961d5 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -489,9 +489,9 @@ def test_numpy_minmax_period(self): def test_min_max_categorical(self): ci = pd.CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): ci.min() - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): ci.max() ci = pd.CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=True) @@ -830,15 +830,15 @@ def test_all_any_params(self): tm.assert_series_equal(s.any(level=0), Series([False, True, True])) # bool_only is not implemented with level option. - with pytest.raises(NotImplementedError, match=msg): + with pytest.raises(NotImplementedError): s.any(bool_only=True, level=0) - with pytest.raises(NotImplementedError, match=msg): + with pytest.raises(NotImplementedError): s.all(bool_only=True, level=0) # bool_only is not implemented alone. - with pytest.raises(NotImplementedError, match=msg): + with pytest.raises(NotImplementedError): s.any(bool_only=True) - with pytest.raises(NotImplementedError, match=msg): + with pytest.raises(NotImplementedError): s.all(bool_only=True) def test_timedelta64_analytics(self): @@ -900,13 +900,13 @@ def test_assert_idxminmax_raises(self, test_input, error_type): """ Cases where ``Series.argmax`` and related should raise an exception """ - with pytest.raises(error_type, match=msg): + with pytest.raises(error_type): test_input.idxmin() - with pytest.raises(error_type, match=msg): + with pytest.raises(error_type): test_input.idxmin(skipna=False) - with pytest.raises(error_type, match=msg): + with pytest.raises(error_type): test_input.idxmax() - with pytest.raises(error_type, match=msg): + with pytest.raises(error_type): test_input.idxmax(skipna=False) def test_idxminmax_with_inf(self): @@ -1001,9 +1001,9 @@ class TestCategoricalSeriesReductions: def test_min_max(self): # unordered cats have no min/max cat = Series(Categorical(["a", "b", "c", "d"], ordered=False)) - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): cat.min() - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError): cat.max() cat = Series(Categorical(["a", "b", "c", "d"], ordered=True))