Skip to content

Commit 3ae1d72

Browse files
andresmcneillSeeminSyed
authored andcommitted
TST: Fix bare pytest raises in generic/test_frame.py (pandas-dev#32565)
1 parent c49dc37 commit 3ae1d72

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

pandas/tests/generic/test_frame.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ def test_nonzero_single_element(self):
7272
assert not df.bool()
7373

7474
df = DataFrame([[False, False]])
75-
with pytest.raises(ValueError):
75+
msg = "The truth value of a DataFrame is ambiguous"
76+
with pytest.raises(ValueError, match=msg):
7677
df.bool()
77-
with pytest.raises(ValueError):
78+
with pytest.raises(ValueError, match=msg):
7879
bool(df)
7980

8081
def test_get_numeric_data_preserve_dtype(self):
@@ -189,30 +190,31 @@ class TestDataFrame2:
189190
def test_validate_bool_args(self, value):
190191
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
191192

192-
with pytest.raises(ValueError):
193+
msg = 'For argument "inplace" expected type bool, received type'
194+
with pytest.raises(ValueError, match=msg):
193195
super(DataFrame, df).rename_axis(
194196
mapper={"a": "x", "b": "y"}, axis=1, inplace=value
195197
)
196198

197-
with pytest.raises(ValueError):
199+
with pytest.raises(ValueError, match=msg):
198200
super(DataFrame, df).drop("a", axis=1, inplace=value)
199201

200-
with pytest.raises(ValueError):
202+
with pytest.raises(ValueError, match=msg):
201203
super(DataFrame, df)._consolidate(inplace=value)
202204

203-
with pytest.raises(ValueError):
205+
with pytest.raises(ValueError, match=msg):
204206
super(DataFrame, df).fillna(value=0, inplace=value)
205207

206-
with pytest.raises(ValueError):
208+
with pytest.raises(ValueError, match=msg):
207209
super(DataFrame, df).replace(to_replace=1, value=7, inplace=value)
208210

209-
with pytest.raises(ValueError):
211+
with pytest.raises(ValueError, match=msg):
210212
super(DataFrame, df).interpolate(inplace=value)
211213

212-
with pytest.raises(ValueError):
214+
with pytest.raises(ValueError, match=msg):
213215
super(DataFrame, df)._where(cond=df.a > 2, inplace=value)
214216

215-
with pytest.raises(ValueError):
217+
with pytest.raises(ValueError, match=msg):
216218
super(DataFrame, df).mask(cond=df.a > 2, inplace=value)
217219

218220
def test_unexpected_keyword(self):
@@ -222,16 +224,17 @@ def test_unexpected_keyword(self):
222224
ts = df["joe"].copy()
223225
ts[2] = np.nan
224226

225-
with pytest.raises(TypeError, match="unexpected keyword"):
227+
msg = "unexpected keyword"
228+
with pytest.raises(TypeError, match=msg):
226229
df.drop("joe", axis=1, in_place=True)
227230

228-
with pytest.raises(TypeError, match="unexpected keyword"):
231+
with pytest.raises(TypeError, match=msg):
229232
df.reindex([1, 0], inplace=True)
230233

231-
with pytest.raises(TypeError, match="unexpected keyword"):
234+
with pytest.raises(TypeError, match=msg):
232235
ca.fillna(0, inplace=True)
233236

234-
with pytest.raises(TypeError, match="unexpected keyword"):
237+
with pytest.raises(TypeError, match=msg):
235238
ts.fillna(0, in_place=True)
236239

237240

0 commit comments

Comments
 (0)