Skip to content

Commit 5e811bd

Browse files
Raisa DzhamtyrovaRaisa Dzhamtyrova
authored andcommitted
split error messages
1 parent 26b3cdf commit 5e811bd

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

pandas/tests/extension/decimal/test_decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class TestMissing(BaseDecimal, base.BaseMissingTests):
146146

147147
class Reduce:
148148
def check_reduce(self, s, op_name, skipna):
149+
149150
if op_name in ["median", "skew", "kurt"]:
150-
# breakpoint()
151151
msg = r"decimal does not support the .* operation"
152152
with pytest.raises(NotImplementedError, match=msg):
153153
getattr(s, op_name)(skipna=skipna)

pandas/tests/frame/indexing/test_categorical.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ def test_assigning_ops(self):
115115
tm.assert_frame_equal(df, exp_single_cats_value)
116116

117117
# - assign a single value not in the current categories set
118-
msg = (
119-
r"(:?Cannot setitem on a Categorical with a new category.*)"
120-
r"|(:?Cannot set a Categorical with another, without identical categories)"
118+
msg1 = (
119+
"Cannot setitem on a Categorical with a new category, "
120+
"set the categories first"
121121
)
122-
with pytest.raises(ValueError, match=msg):
122+
msg2 = "Cannot set a Categorical with another, without identical categories"
123+
with pytest.raises(ValueError, match=msg1):
123124
df = orig.copy()
124125
df.iloc[2, 0] = "c"
125126

@@ -129,7 +130,7 @@ def test_assigning_ops(self):
129130
tm.assert_frame_equal(df, exp_single_row)
130131

131132
# - assign a complete row (mixed values) not in categories set
132-
with pytest.raises(ValueError, match=msg):
133+
with pytest.raises(ValueError, match=msg1):
133134
df = orig.copy()
134135
df.iloc[2, :] = ["c", 2]
135136

@@ -138,7 +139,7 @@ def test_assigning_ops(self):
138139
df.iloc[2:4, :] = [["b", 2], ["b", 2]]
139140
tm.assert_frame_equal(df, exp_multi_row)
140141

141-
with pytest.raises(ValueError, match=msg):
142+
with pytest.raises(ValueError, match=msg1):
142143
df = orig.copy()
143144
df.iloc[2:4, :] = [["c", 2], ["c", 2]]
144145

@@ -148,12 +149,12 @@ def test_assigning_ops(self):
148149
df.iloc[2:4, 0] = Categorical(["b", "b"], categories=["a", "b"])
149150
tm.assert_frame_equal(df, exp_parts_cats_col)
150151

151-
with pytest.raises(ValueError, match=msg):
152+
with pytest.raises(ValueError, match=msg2):
152153
# different categories -> not sure if this should fail or pass
153154
df = orig.copy()
154155
df.iloc[2:4, 0] = Categorical(list("bb"), categories=list("abc"))
155156

156-
with pytest.raises(ValueError, match=msg):
157+
with pytest.raises(ValueError, match=msg2):
157158
# different values
158159
df = orig.copy()
159160
df.iloc[2:4, 0] = Categorical(list("cc"), categories=list("abc"))
@@ -164,7 +165,7 @@ def test_assigning_ops(self):
164165
df.iloc[2:4, 0] = ["b", "b"]
165166
tm.assert_frame_equal(df, exp_parts_cats_col)
166167

167-
with pytest.raises(ValueError, match=msg):
168+
with pytest.raises(ValueError, match=msg1):
168169
df.iloc[2:4, 0] = ["c", "c"]
169170

170171
# loc
@@ -179,7 +180,7 @@ def test_assigning_ops(self):
179180
tm.assert_frame_equal(df, exp_single_cats_value)
180181

181182
# - assign a single value not in the current categories set
182-
with pytest.raises(ValueError, match=msg):
183+
with pytest.raises(ValueError, match=msg1):
183184
df = orig.copy()
184185
df.loc["j", "cats"] = "c"
185186

@@ -189,7 +190,7 @@ def test_assigning_ops(self):
189190
tm.assert_frame_equal(df, exp_single_row)
190191

191192
# - assign a complete row (mixed values) not in categories set
192-
with pytest.raises(ValueError, match=msg):
193+
with pytest.raises(ValueError, match=msg1):
193194
df = orig.copy()
194195
df.loc["j", :] = ["c", 2]
195196

@@ -198,7 +199,7 @@ def test_assigning_ops(self):
198199
df.loc["j":"k", :] = [["b", 2], ["b", 2]]
199200
tm.assert_frame_equal(df, exp_multi_row)
200201

201-
with pytest.raises(ValueError, match=msg):
202+
with pytest.raises(ValueError, match=msg1):
202203
df = orig.copy()
203204
df.loc["j":"k", :] = [["c", 2], ["c", 2]]
204205

@@ -208,14 +209,14 @@ def test_assigning_ops(self):
208209
df.loc["j":"k", "cats"] = Categorical(["b", "b"], categories=["a", "b"])
209210
tm.assert_frame_equal(df, exp_parts_cats_col)
210211

211-
with pytest.raises(ValueError, match=msg):
212+
with pytest.raises(ValueError, match=msg2):
212213
# different categories -> not sure if this should fail or pass
213214
df = orig.copy()
214215
df.loc["j":"k", "cats"] = Categorical(
215216
["b", "b"], categories=["a", "b", "c"]
216217
)
217218

218-
with pytest.raises(ValueError, match=msg):
219+
with pytest.raises(ValueError, match=msg2):
219220
# different values
220221
df = orig.copy()
221222
df.loc["j":"k", "cats"] = Categorical(
@@ -228,7 +229,7 @@ def test_assigning_ops(self):
228229
df.loc["j":"k", "cats"] = ["b", "b"]
229230
tm.assert_frame_equal(df, exp_parts_cats_col)
230231

231-
with pytest.raises(ValueError, match=msg):
232+
with pytest.raises(ValueError, match=msg1):
232233
df.loc["j":"k", "cats"] = ["c", "c"]
233234

234235
# loc
@@ -243,7 +244,7 @@ def test_assigning_ops(self):
243244
tm.assert_frame_equal(df, exp_single_cats_value)
244245

245246
# - assign a single value not in the current categories set
246-
with pytest.raises(ValueError, match=msg):
247+
with pytest.raises(ValueError, match=msg1):
247248
df = orig.copy()
248249
df.loc["j", df.columns[0]] = "c"
249250

@@ -253,7 +254,7 @@ def test_assigning_ops(self):
253254
tm.assert_frame_equal(df, exp_single_row)
254255

255256
# - assign a complete row (mixed values) not in categories set
256-
with pytest.raises(ValueError, match=msg):
257+
with pytest.raises(ValueError, match=msg1):
257258
df = orig.copy()
258259
df.loc["j", :] = ["c", 2]
259260

@@ -262,7 +263,7 @@ def test_assigning_ops(self):
262263
df.loc["j":"k", :] = [["b", 2], ["b", 2]]
263264
tm.assert_frame_equal(df, exp_multi_row)
264265

265-
with pytest.raises(ValueError, match=msg):
266+
with pytest.raises(ValueError, match=msg1):
266267
df = orig.copy()
267268
df.loc["j":"k", :] = [["c", 2], ["c", 2]]
268269

@@ -272,14 +273,14 @@ def test_assigning_ops(self):
272273
df.loc["j":"k", df.columns[0]] = Categorical(["b", "b"], categories=["a", "b"])
273274
tm.assert_frame_equal(df, exp_parts_cats_col)
274275

275-
with pytest.raises(ValueError, match=msg):
276+
with pytest.raises(ValueError, match=msg2):
276277
# different categories -> not sure if this should fail or pass
277278
df = orig.copy()
278279
df.loc["j":"k", df.columns[0]] = Categorical(
279280
["b", "b"], categories=["a", "b", "c"]
280281
)
281282

282-
with pytest.raises(ValueError, match=msg):
283+
with pytest.raises(ValueError, match=msg2):
283284
# different values
284285
df = orig.copy()
285286
df.loc["j":"k", df.columns[0]] = Categorical(
@@ -292,7 +293,7 @@ def test_assigning_ops(self):
292293
df.loc["j":"k", df.columns[0]] = ["b", "b"]
293294
tm.assert_frame_equal(df, exp_parts_cats_col)
294295

295-
with pytest.raises(ValueError, match=msg):
296+
with pytest.raises(ValueError, match=msg1):
296297
df.loc["j":"k", df.columns[0]] = ["c", "c"]
297298

298299
# iat
@@ -301,7 +302,7 @@ def test_assigning_ops(self):
301302
tm.assert_frame_equal(df, exp_single_cats_value)
302303

303304
# - assign a single value not in the current categories set
304-
with pytest.raises(ValueError, match=msg):
305+
with pytest.raises(ValueError, match=msg1):
305306
df = orig.copy()
306307
df.iat[2, 0] = "c"
307308

@@ -312,7 +313,7 @@ def test_assigning_ops(self):
312313
tm.assert_frame_equal(df, exp_single_cats_value)
313314

314315
# - assign a single value not in the current categories set
315-
with pytest.raises(ValueError, match=msg):
316+
with pytest.raises(ValueError, match=msg1):
316317
df = orig.copy()
317318
df.at["j", "cats"] = "c"
318319

@@ -336,7 +337,7 @@ def test_assigning_ops(self):
336337
df.at["j", "cats"] = "b"
337338
tm.assert_frame_equal(df, exp_single_cats_value)
338339

339-
with pytest.raises(ValueError, match=msg):
340+
with pytest.raises(ValueError, match=msg1):
340341
df = orig.copy()
341342
df.at["j", "cats"] = "c"
342343

pandas/tests/frame/methods/test_explode.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ def test_error():
99
df = pd.DataFrame(
1010
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
1111
)
12-
msg = r"(:?columns must be unique)|(:?column must be a scalar)"
13-
with pytest.raises(ValueError, match=msg):
12+
with pytest.raises(ValueError, match="column must be a scalar"):
1413
df.explode(list("AA"))
1514

1615
df.columns = list("AA")
17-
with pytest.raises(ValueError, match=msg):
16+
with pytest.raises(ValueError, match="columns must be unique"):
1817
df.explode("A")
1918

2019

pandas/tests/frame/methods/test_isin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def test_isin_with_string_scalar(self):
6060
},
6161
index=["foo", "bar", "baz", "qux"],
6262
)
63-
msg = r"only list-like or dict-like objects are allowed"
64-
r"to be passed to DataFrame.isin\(\), you passed a 'str'"
63+
msg = (
64+
r"only list-like or dict-like objects are allowed"
65+
r"to be passed to DataFrame.isin\(\), you passed a 'str'"
66+
)
6567
with pytest.raises(TypeError, match=msg):
6668
df.isin("a")
6769

pandas/tests/frame/methods/test_replace.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,10 @@ def test_categorical_replace_with_dict(self, replace_dict, final_data):
13081308
expected["b"] = expected["b"].cat.set_categories([1, 2, 3])
13091309
result = df.replace(replace_dict, 3)
13101310
tm.assert_frame_equal(result, expected)
1311-
msg = r"Attributes of DataFrame.iloc\[:, 0\]"
1312-
r"\(column name=\"a\"\) are different.*"
1311+
msg = (
1312+
r"Attributes of DataFrame.iloc\[:, 0\] "
1313+
r"\(column name=\"a\"\) are different.*"
1314+
)
13131315
with pytest.raises(AssertionError, match=msg):
13141316
# ensure non-inplace call does not affect original
13151317
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)