Skip to content

Commit bc5c6c4

Browse files
committed
Issue #pandas-dev#30999, Added match = msg as a second parameter in applicable lines.
1 parent 6b87716 commit bc5c6c4

10 files changed

+72
-72
lines changed

pandas/tests/io/test_html.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ def test_file_like(self):
276276

277277
@tm.network
278278
def test_bad_url_protocol(self):
279-
with pytest.raises(URLError):
279+
with pytest.raises(URLError, match=msg):
280280
self.read_html("git://github.com", match=".*Water.*")
281281

282282
@tm.network
283283
@pytest.mark.slow
284284
def test_invalid_url(self):
285285
try:
286-
with pytest.raises(URLError):
286+
with pytest.raises(URLError, match=msg):
287287
self.read_html("http://www.a23950sdfa908sd.com", match=".*Water.*")
288288
except ValueError as e:
289289
assert "No tables found" in str(e)
@@ -357,7 +357,7 @@ def test_regex_idempotency(self):
357357

358358
def test_negative_skiprows(self):
359359
msg = r"\(you passed a negative value\)"
360-
with pytest.raises(ValueError, match=msg):
360+
with (ValueError, match=msg):
361361
self.read_html(self.spam_data, "Water", skiprows=-1)
362362

363363
@tm.network
@@ -964,7 +964,7 @@ def test_decimal_rows(self):
964964
def test_bool_header_arg(self):
965965
# GH 6114
966966
for arg in [True, False]:
967-
with pytest.raises(TypeError):
967+
with pytest.raises(TypeError, match=msg):
968968
self.read_html(self.spam_data, header=arg)
969969

970970
def test_converters(self):

pandas/tests/io/test_parquet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def compare(repeat):
178178

179179

180180
def test_invalid_engine(df_compat):
181-
with pytest.raises(ValueError):
181+
with pytest.raises(ValueError, match=msg):
182182
check_round_trip(df_compat, "foo", "bar")
183183

184184

@@ -667,7 +667,7 @@ def test_error_on_using_partition_cols_and_partition_on(self, fp, df_full):
667667
# GH #23283
668668
partition_cols = ["bool", "int"]
669669
df = df_full
670-
with pytest.raises(ValueError):
670+
with pytest.raises(ValueError, match=msg):
671671
with tm.ensure_clean_dir() as path:
672672
df.to_parquet(
673673
path,

pandas/tests/io/test_sql.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ def test_execute_fail(self):
24172417
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn)
24182418
sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn)
24192419

2420-
with pytest.raises(Exception):
2420+
with pytest.raises(Exception, match=msg):
24212421
sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn)
24222422

24232423
def test_execute_closed_connection(self):
@@ -2436,7 +2436,7 @@ def test_execute_closed_connection(self):
24362436
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn)
24372437
self.conn.close()
24382438

2439-
with pytest.raises(Exception):
2439+
with pytest.raises(Exception, match=msg):
24402440
tquery("select * from test", con=self.conn)
24412441

24422442
def test_na_roundtrip(self):
@@ -2700,7 +2700,7 @@ def test_execute_fail(self):
27002700
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn)
27012701
sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', self.conn)
27022702

2703-
with pytest.raises(Exception):
2703+
with pytest.raises(Exception, match=msg):
27042704
sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn)
27052705

27062706
def test_execute_closed_connection(self, request, datapath):
@@ -2721,7 +2721,7 @@ def test_execute_closed_connection(self, request, datapath):
27212721
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', self.conn)
27222722
self.conn.close()
27232723

2724-
with pytest.raises(Exception):
2724+
with pytest.raises(Exception, match=msg):
27252725
tquery("select * from test", con=self.conn)
27262726

27272727
# Initialize connection again (needed for tearDown)

pandas/tests/io/test_stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ def test_unsupported_datetype(self):
13741374
"dates": dates,
13751375
}
13761376
)
1377-
with pytest.raises(NotImplementedError):
1377+
with pytest.raises(NotImplementedError, match=msg):
13781378
with tm.ensure_clean() as path:
13791379
original.to_stata(path)
13801380

pandas/tests/plotting/test_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_setting_backend_without_plot_raises():
9292

9393
@td.skip_if_mpl
9494
def test_no_matplotlib_ok():
95-
with pytest.raises(ImportError):
95+
with pytest.raises(ImportError, match=msg):
9696
pandas.plotting._core._get_plot_backend("matplotlib")
9797

9898

pandas/tests/plotting/test_boxplot_method.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_boxplot_return_type_legacy(self):
9696
index=list(string.ascii_letters[:6]),
9797
columns=["one", "two", "three", "four"],
9898
)
99-
with pytest.raises(ValueError):
99+
with pytest.raises(ValueError, match=msg):
100100
df.boxplot(return_type="NOTATYPE")
101101

102102
result = df.boxplot()
@@ -429,7 +429,7 @@ def test_grouped_box_multiple_axes(self):
429429
tm.assert_numpy_array_equal(returned, axes[1])
430430
assert returned[0].figure is fig
431431

432-
with pytest.raises(ValueError):
432+
with pytest.raises(ValueError, match=msg):
433433
fig, axes = self.plt.subplots(2, 3)
434434
# pass different number of axes from required
435435
with tm.assert_produces_warning(UserWarning):

pandas/tests/plotting/test_frame.py

+27-27
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_rgb_tuple_color(self):
187187

188188
def test_color_empty_string(self):
189189
df = DataFrame(randn(10, 2))
190-
with pytest.raises(ValueError):
190+
with pytest.raises(ValueError, match=msg):
191191
df.plot(color="")
192192

193193
def test_color_and_style_arguments(self):
@@ -203,7 +203,7 @@ def test_color_and_style_arguments(self):
203203
assert color == ["red", "black"]
204204
# passing both 'color' and 'style' arguments should not be allowed
205205
# if there is a color symbol in the style strings:
206-
with pytest.raises(ValueError):
206+
with pytest.raises(ValueError, match=msg):
207207
df.plot(color=["red", "black"], style=["k-", "r--"])
208208

209209
def test_nonnumeric_exclude(self):
@@ -628,9 +628,9 @@ def test_subplots_layout(self):
628628
self._check_axes_shape(axes, axes_num=3, layout=(4, 1))
629629
assert axes.shape == (4, 1)
630630

631-
with pytest.raises(ValueError):
631+
with pytest.raises(ValueError, match=msg):
632632
df.plot(subplots=True, layout=(1, 1))
633-
with pytest.raises(ValueError):
633+
with pytest.raises(ValueError, match=msg):
634634
df.plot(subplots=True, layout=(-1, -1))
635635

636636
# single column
@@ -673,7 +673,7 @@ def test_subplots_multiple_axes(self):
673673
self._check_axes_shape(axes, axes_num=6, layout=(2, 3))
674674
tm.close()
675675

676-
with pytest.raises(ValueError):
676+
with pytest.raises(ValueError, match=msg):
677677
fig, axes = self.plt.subplots(2, 3)
678678
# pass different number of axes from required
679679
df.plot(subplots=True, ax=axes)
@@ -784,9 +784,9 @@ def test_negative_log(self):
784784
columns=["x", "y", "z", "four"],
785785
)
786786

787-
with pytest.raises(ValueError):
787+
with pytest.raises(ValueError, match=msg):
788788
df.plot.area(logy=True)
789-
with pytest.raises(ValueError):
789+
with pytest.raises(ValueError, match=msg):
790790
df.plot.area(loglog=True)
791791

792792
def _compare_stacked_y_cood(self, normal_lines, stacked_lines):
@@ -826,7 +826,7 @@ def test_line_area_stacked(self):
826826
self._compare_stacked_y_cood(ax1.lines[2:], ax2.lines[2:])
827827

828828
_check_plot_works(mixed_df.plot, stacked=False)
829-
with pytest.raises(ValueError):
829+
with pytest.raises(ValueError, match=msg):
830830
mixed_df.plot(stacked=True)
831831

832832
# Use an index with strictly positive values, preventing
@@ -1153,9 +1153,9 @@ def test_plot_scatter(self):
11531153
_check_plot_works(df.plot.scatter, x="x", y="y")
11541154
_check_plot_works(df.plot.scatter, x=1, y=2)
11551155

1156-
with pytest.raises(TypeError):
1156+
with pytest.raises(TypeError, match=msg):
11571157
df.plot.scatter(x="x")
1158-
with pytest.raises(TypeError):
1158+
with pytest.raises(TypeError, match=msg):
11591159
df.plot.scatter(y="y")
11601160

11611161
# GH 6951
@@ -1310,7 +1310,7 @@ def test_plot_scatter_with_c(self):
13101310

13111311
def test_scatter_colors(self):
13121312
df = DataFrame({"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3]})
1313-
with pytest.raises(TypeError):
1313+
with pytest.raises(TypeError, match=msg):
13141314
df.plot.scatter(x="a", y="b", c="c", color="green")
13151315

13161316
default_colors = self._unpack_cycler(self.plt.rcParams)
@@ -1580,7 +1580,7 @@ def test_boxplot_return_type(self):
15801580
index=list(string.ascii_letters[:6]),
15811581
columns=["one", "two", "three", "four"],
15821582
)
1583-
with pytest.raises(ValueError):
1583+
with pytest.raises(ValueError, match=msg):
15841584
df.plot.box(return_type="NOTATYPE")
15851585

15861586
result = df.plot.box(return_type="dict")
@@ -2036,7 +2036,7 @@ def test_line_colors(self):
20362036
self._check_colors(ax.get_lines(), linecolors=custom_colors)
20372037
tm.close()
20382038

2039-
with pytest.raises(ValueError):
2039+
with pytest.raises(ValueError, match=msg):
20402040
# Color contains shorthand hex value results in ValueError
20412041
custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"]
20422042
# Forced show plot
@@ -2093,7 +2093,7 @@ def test_line_colors_and_styles_subplots(self):
20932093
self._check_colors(ax.get_lines(), linecolors=[c])
20942094
tm.close()
20952095

2096-
with pytest.raises(ValueError):
2096+
with pytest.raises(ValueError, match=msg):
20972097
# Color contains shorthand hex value results in ValueError
20982098
custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"]
20992099
# Forced show plot
@@ -2348,7 +2348,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None):
23482348
bp = df.plot.box(color=(0, 1, 0), sym="#123456", return_type="dict")
23492349
_check_colors(bp, (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), "#123456")
23502350

2351-
with pytest.raises(ValueError):
2351+
with pytest.raises(ValueError, match=msg):
23522352
# Color contains invalid key results in ValueError
23532353
df.plot.box(color=dict(boxes="red", xxxx="blue"))
23542354

@@ -2413,12 +2413,12 @@ def test_partially_invalid_plot_data(self):
24132413
df = DataFrame(rand(10, 2), dtype=object)
24142414
df[np.random.rand(df.shape[0]) > 0.5] = "a"
24152415
for kind in kinds:
2416-
with pytest.raises(TypeError):
2416+
with pytest.raises(TypeError, match=msg):
24172417
df.plot(kind=kind)
24182418

24192419
def test_invalid_kind(self):
24202420
df = DataFrame(randn(10, 2))
2421-
with pytest.raises(ValueError):
2421+
with pytest.raises(ValueError, match=msg):
24222422
df.plot(kind="aasdf")
24232423

24242424
@pytest.mark.parametrize(
@@ -2432,14 +2432,14 @@ def test_invalid_kind(self):
24322432
def test_invalid_xy_args(self, x, y, lbl):
24332433
# GH 18671, 19699 allows y to be list-like but not x
24342434
df = DataFrame({"A": [1, 2], "B": [3, 4], "C": [5, 6]})
2435-
with pytest.raises(ValueError):
2435+
with pytest.raises(ValueError, match=msg):
24362436
df.plot(x=x, y=y, label=lbl)
24372437

24382438
@pytest.mark.parametrize("x,y", [("A", "B"), (["A"], "B")])
24392439
def test_invalid_xy_args_dup_cols(self, x, y):
24402440
# GH 18671, 19699 allows y to be list-like but not x
24412441
df = DataFrame([[1, 3, 5], [2, 4, 6]], columns=list("AAB"))
2442-
with pytest.raises(ValueError):
2442+
with pytest.raises(ValueError, match=msg):
24432443
df.plot(x=x, y=y)
24442444

24452445
@pytest.mark.parametrize(
@@ -2518,7 +2518,7 @@ def test_allow_cmap(self):
25182518
ax = df.plot.hexbin(x="A", y="B", cmap="YlGn")
25192519
assert ax.collections[0].cmap.name == "YlGn"
25202520

2521-
with pytest.raises(TypeError):
2521+
with pytest.raises(TypeError, match=msg):
25222522
df.plot.hexbin(x="A", y="B", cmap="YlGn", colormap="BuGn")
25232523

25242524
@pytest.mark.slow
@@ -2528,7 +2528,7 @@ def test_pie_df(self):
25282528
columns=["X", "Y", "Z"],
25292529
index=["a", "b", "c", "d", "e"],
25302530
)
2531-
with pytest.raises(ValueError):
2531+
with pytest.raises(ValueError, match=msg):
25322532
df.plot.pie()
25332533

25342534
ax = _check_plot_works(df.plot.pie, y="Y")
@@ -2635,11 +2635,11 @@ def test_errorbar_plot(self):
26352635
ax = _check_plot_works(s_df.plot, y="y", x="x", yerr=yerr)
26362636
self._check_has_errorbars(ax, xerr=0, yerr=1)
26372637

2638-
with pytest.raises(ValueError):
2638+
with pytest.raises(ValueError, match=msg):
26392639
df.plot(yerr=np.random.randn(11))
26402640

26412641
df_err = DataFrame({"x": ["zzz"] * 12, "y": ["zzz"] * 12})
2642-
with pytest.raises((ValueError, TypeError)):
2642+
with pytest.raises((ValueError, TypeError), match=msg):
26432643
df.plot(yerr=df_err)
26442644

26452645
@pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError)
@@ -2731,7 +2731,7 @@ def test_errorbar_asymmetrical(self):
27312731
expected_0_0 = err[0, :, 0] * np.array([-1, 1])
27322732
tm.assert_almost_equal(yerr_0_0, expected_0_0)
27332733

2734-
with pytest.raises(ValueError):
2734+
with pytest.raises(ValueError, match=msg):
27352735
df.plot(yerr=err.T)
27362736

27372737
tm.close()
@@ -2923,7 +2923,7 @@ def test_memory_leak(self):
29232923
gc.collect()
29242924
for key in results:
29252925
# check that every plot was collected
2926-
with pytest.raises(ReferenceError):
2926+
with pytest.raises(ReferenceError, match=msg):
29272927
# need to actually access something to get an error
29282928
results[key].lines
29292929

@@ -3102,7 +3102,7 @@ def test_df_grid_settings(self):
31023102
def test_invalid_colormap(self):
31033103
df = DataFrame(randn(3, 2), columns=["A", "B"])
31043104

3105-
with pytest.raises(ValueError):
3105+
with pytest.raises(ValueError, match=msg):
31063106
df.plot(colormap="invalid_colormap")
31073107

31083108
def test_plain_axes(self):
@@ -3268,7 +3268,7 @@ def test_plot_no_rows(self):
32683268

32693269
def test_plot_no_numeric_data(self):
32703270
df = pd.DataFrame(["a", "b", "c"])
3271-
with pytest.raises(TypeError):
3271+
with pytest.raises(TypeError, match=msg):
32723272
df.plot()
32733273

32743274
def test_missing_markers_legend(self):

0 commit comments

Comments
 (0)