@@ -115,11 +115,12 @@ def test_assigning_ops(self):
115
115
tm .assert_frame_equal (df , exp_single_cats_value )
116
116
117
117
# - 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 "
121
121
)
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 ):
123
124
df = orig .copy ()
124
125
df .iloc [2 , 0 ] = "c"
125
126
@@ -129,7 +130,7 @@ def test_assigning_ops(self):
129
130
tm .assert_frame_equal (df , exp_single_row )
130
131
131
132
# - assign a complete row (mixed values) not in categories set
132
- with pytest .raises (ValueError , match = msg ):
133
+ with pytest .raises (ValueError , match = msg1 ):
133
134
df = orig .copy ()
134
135
df .iloc [2 , :] = ["c" , 2 ]
135
136
@@ -138,7 +139,7 @@ def test_assigning_ops(self):
138
139
df .iloc [2 :4 , :] = [["b" , 2 ], ["b" , 2 ]]
139
140
tm .assert_frame_equal (df , exp_multi_row )
140
141
141
- with pytest .raises (ValueError , match = msg ):
142
+ with pytest .raises (ValueError , match = msg1 ):
142
143
df = orig .copy ()
143
144
df .iloc [2 :4 , :] = [["c" , 2 ], ["c" , 2 ]]
144
145
@@ -148,12 +149,12 @@ def test_assigning_ops(self):
148
149
df .iloc [2 :4 , 0 ] = Categorical (["b" , "b" ], categories = ["a" , "b" ])
149
150
tm .assert_frame_equal (df , exp_parts_cats_col )
150
151
151
- with pytest .raises (ValueError , match = msg ):
152
+ with pytest .raises (ValueError , match = msg2 ):
152
153
# different categories -> not sure if this should fail or pass
153
154
df = orig .copy ()
154
155
df .iloc [2 :4 , 0 ] = Categorical (list ("bb" ), categories = list ("abc" ))
155
156
156
- with pytest .raises (ValueError , match = msg ):
157
+ with pytest .raises (ValueError , match = msg2 ):
157
158
# different values
158
159
df = orig .copy ()
159
160
df .iloc [2 :4 , 0 ] = Categorical (list ("cc" ), categories = list ("abc" ))
@@ -164,7 +165,7 @@ def test_assigning_ops(self):
164
165
df .iloc [2 :4 , 0 ] = ["b" , "b" ]
165
166
tm .assert_frame_equal (df , exp_parts_cats_col )
166
167
167
- with pytest .raises (ValueError , match = msg ):
168
+ with pytest .raises (ValueError , match = msg1 ):
168
169
df .iloc [2 :4 , 0 ] = ["c" , "c" ]
169
170
170
171
# loc
@@ -179,7 +180,7 @@ def test_assigning_ops(self):
179
180
tm .assert_frame_equal (df , exp_single_cats_value )
180
181
181
182
# - assign a single value not in the current categories set
182
- with pytest .raises (ValueError , match = msg ):
183
+ with pytest .raises (ValueError , match = msg1 ):
183
184
df = orig .copy ()
184
185
df .loc ["j" , "cats" ] = "c"
185
186
@@ -189,7 +190,7 @@ def test_assigning_ops(self):
189
190
tm .assert_frame_equal (df , exp_single_row )
190
191
191
192
# - assign a complete row (mixed values) not in categories set
192
- with pytest .raises (ValueError , match = msg ):
193
+ with pytest .raises (ValueError , match = msg1 ):
193
194
df = orig .copy ()
194
195
df .loc ["j" , :] = ["c" , 2 ]
195
196
@@ -198,7 +199,7 @@ def test_assigning_ops(self):
198
199
df .loc ["j" :"k" , :] = [["b" , 2 ], ["b" , 2 ]]
199
200
tm .assert_frame_equal (df , exp_multi_row )
200
201
201
- with pytest .raises (ValueError , match = msg ):
202
+ with pytest .raises (ValueError , match = msg1 ):
202
203
df = orig .copy ()
203
204
df .loc ["j" :"k" , :] = [["c" , 2 ], ["c" , 2 ]]
204
205
@@ -208,14 +209,14 @@ def test_assigning_ops(self):
208
209
df .loc ["j" :"k" , "cats" ] = Categorical (["b" , "b" ], categories = ["a" , "b" ])
209
210
tm .assert_frame_equal (df , exp_parts_cats_col )
210
211
211
- with pytest .raises (ValueError , match = msg ):
212
+ with pytest .raises (ValueError , match = msg2 ):
212
213
# different categories -> not sure if this should fail or pass
213
214
df = orig .copy ()
214
215
df .loc ["j" :"k" , "cats" ] = Categorical (
215
216
["b" , "b" ], categories = ["a" , "b" , "c" ]
216
217
)
217
218
218
- with pytest .raises (ValueError , match = msg ):
219
+ with pytest .raises (ValueError , match = msg2 ):
219
220
# different values
220
221
df = orig .copy ()
221
222
df .loc ["j" :"k" , "cats" ] = Categorical (
@@ -228,7 +229,7 @@ def test_assigning_ops(self):
228
229
df .loc ["j" :"k" , "cats" ] = ["b" , "b" ]
229
230
tm .assert_frame_equal (df , exp_parts_cats_col )
230
231
231
- with pytest .raises (ValueError , match = msg ):
232
+ with pytest .raises (ValueError , match = msg1 ):
232
233
df .loc ["j" :"k" , "cats" ] = ["c" , "c" ]
233
234
234
235
# loc
@@ -243,7 +244,7 @@ def test_assigning_ops(self):
243
244
tm .assert_frame_equal (df , exp_single_cats_value )
244
245
245
246
# - assign a single value not in the current categories set
246
- with pytest .raises (ValueError , match = msg ):
247
+ with pytest .raises (ValueError , match = msg1 ):
247
248
df = orig .copy ()
248
249
df .loc ["j" , df .columns [0 ]] = "c"
249
250
@@ -253,7 +254,7 @@ def test_assigning_ops(self):
253
254
tm .assert_frame_equal (df , exp_single_row )
254
255
255
256
# - assign a complete row (mixed values) not in categories set
256
- with pytest .raises (ValueError , match = msg ):
257
+ with pytest .raises (ValueError , match = msg1 ):
257
258
df = orig .copy ()
258
259
df .loc ["j" , :] = ["c" , 2 ]
259
260
@@ -262,7 +263,7 @@ def test_assigning_ops(self):
262
263
df .loc ["j" :"k" , :] = [["b" , 2 ], ["b" , 2 ]]
263
264
tm .assert_frame_equal (df , exp_multi_row )
264
265
265
- with pytest .raises (ValueError , match = msg ):
266
+ with pytest .raises (ValueError , match = msg1 ):
266
267
df = orig .copy ()
267
268
df .loc ["j" :"k" , :] = [["c" , 2 ], ["c" , 2 ]]
268
269
@@ -272,14 +273,14 @@ def test_assigning_ops(self):
272
273
df .loc ["j" :"k" , df .columns [0 ]] = Categorical (["b" , "b" ], categories = ["a" , "b" ])
273
274
tm .assert_frame_equal (df , exp_parts_cats_col )
274
275
275
- with pytest .raises (ValueError , match = msg ):
276
+ with pytest .raises (ValueError , match = msg2 ):
276
277
# different categories -> not sure if this should fail or pass
277
278
df = orig .copy ()
278
279
df .loc ["j" :"k" , df .columns [0 ]] = Categorical (
279
280
["b" , "b" ], categories = ["a" , "b" , "c" ]
280
281
)
281
282
282
- with pytest .raises (ValueError , match = msg ):
283
+ with pytest .raises (ValueError , match = msg2 ):
283
284
# different values
284
285
df = orig .copy ()
285
286
df .loc ["j" :"k" , df .columns [0 ]] = Categorical (
@@ -292,7 +293,7 @@ def test_assigning_ops(self):
292
293
df .loc ["j" :"k" , df .columns [0 ]] = ["b" , "b" ]
293
294
tm .assert_frame_equal (df , exp_parts_cats_col )
294
295
295
- with pytest .raises (ValueError , match = msg ):
296
+ with pytest .raises (ValueError , match = msg1 ):
296
297
df .loc ["j" :"k" , df .columns [0 ]] = ["c" , "c" ]
297
298
298
299
# iat
@@ -301,7 +302,7 @@ def test_assigning_ops(self):
301
302
tm .assert_frame_equal (df , exp_single_cats_value )
302
303
303
304
# - assign a single value not in the current categories set
304
- with pytest .raises (ValueError , match = msg ):
305
+ with pytest .raises (ValueError , match = msg1 ):
305
306
df = orig .copy ()
306
307
df .iat [2 , 0 ] = "c"
307
308
@@ -312,7 +313,7 @@ def test_assigning_ops(self):
312
313
tm .assert_frame_equal (df , exp_single_cats_value )
313
314
314
315
# - assign a single value not in the current categories set
315
- with pytest .raises (ValueError , match = msg ):
316
+ with pytest .raises (ValueError , match = msg1 ):
316
317
df = orig .copy ()
317
318
df .at ["j" , "cats" ] = "c"
318
319
@@ -336,7 +337,7 @@ def test_assigning_ops(self):
336
337
df .at ["j" , "cats" ] = "b"
337
338
tm .assert_frame_equal (df , exp_single_cats_value )
338
339
339
- with pytest .raises (ValueError , match = msg ):
340
+ with pytest .raises (ValueError , match = msg1 ):
340
341
df = orig .copy ()
341
342
df .at ["j" , "cats" ] = "c"
342
343
0 commit comments