@@ -164,27 +164,27 @@ def test_str_cat(self, box):
164
164
165
165
# single array
166
166
result = s .str .cat ()
167
- exp = 'aabbc'
168
- assert result == exp
167
+ expected = 'aabbc'
168
+ assert result == expected
169
169
170
170
result = s .str .cat (na_rep = '-' )
171
- exp = 'aabbc-'
172
- assert result == exp
171
+ expected = 'aabbc-'
172
+ assert result == expected
173
173
174
174
result = s .str .cat (sep = '_' , na_rep = 'NA' )
175
- exp = 'a_a_b_b_c_NA'
176
- assert result == exp
175
+ expected = 'a_a_b_b_c_NA'
176
+ assert result == expected
177
177
178
178
t = np .array (['a' , np .nan , 'b' , 'd' , 'foo' , np .nan ], dtype = object )
179
- exp = box (['aa' , 'a-' , 'bb' , 'bd' , 'cfoo' , '--' ])
179
+ expected = box (['aa' , 'a-' , 'bb' , 'bd' , 'cfoo' , '--' ])
180
180
181
181
# Series/Index with array
182
182
result = s .str .cat (t , na_rep = '-' )
183
- assert_series_or_index_equal (result , exp )
183
+ assert_series_or_index_equal (result , expected )
184
184
185
185
# Series/Index with list
186
186
result = s .str .cat (list (t ), na_rep = '-' )
187
- assert_series_or_index_equal (result , exp )
187
+ assert_series_or_index_equal (result , expected )
188
188
189
189
# errors for incorrect lengths
190
190
rgx = 'All arrays must be same length, except those having an index.*'
@@ -217,30 +217,30 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target):
217
217
s = s if box == Index else Series (s , index = s )
218
218
t = Index (['b' , 'a' , 'b' , 'c' ], dtype = dtype_target )
219
219
220
- exp = Index (['ab' , 'aa' , 'bb' , 'ac' ])
221
- exp = exp if box == Index else Series (exp , index = s )
220
+ expected = Index (['ab' , 'aa' , 'bb' , 'ac' ])
221
+ expected = expected if box == Index else Series (expected , index = s )
222
222
223
223
# Series/Index with unaligned Index
224
224
with tm .assert_produces_warning (expected_warning = FutureWarning ):
225
225
# FutureWarning to switch to alignment by default
226
226
result = s .str .cat (t )
227
- assert_series_or_index_equal (result , exp )
227
+ assert_series_or_index_equal (result , expected )
228
228
229
229
# Series/Index with Series having matching Index
230
230
t = Series (t , index = s )
231
231
result = s .str .cat (t )
232
- assert_series_or_index_equal (result , exp )
232
+ assert_series_or_index_equal (result , expected )
233
233
234
234
# Series/Index with Series.values
235
235
result = s .str .cat (t .values )
236
- assert_series_or_index_equal (result , exp )
236
+ assert_series_or_index_equal (result , expected )
237
237
238
238
# Series/Index with Series having different Index
239
239
t = Series (t .values , index = t )
240
240
with tm .assert_produces_warning (expected_warning = FutureWarning ):
241
241
# FutureWarning to switch to alignment by default
242
242
result = s .str .cat (t )
243
- assert_series_or_index_equal (result , exp )
243
+ assert_series_or_index_equal (result , expected )
244
244
245
245
@pytest .mark .parametrize ('box' , [Series , Index ])
246
246
def test_str_cat_mixed_inputs (self , box ):
@@ -250,56 +250,57 @@ def test_str_cat_mixed_inputs(self, box):
250
250
t = Series (['A' , 'B' , 'C' , 'D' ], index = s .values )
251
251
d = concat ([t , Series (s , index = s )], axis = 1 )
252
252
253
- exp = Index (['aAa' , 'bBb' , 'cCc' , 'dDd' ])
254
- exp = exp if box == Index else Series (exp .values , index = s .values )
253
+ expected = Index (['aAa' , 'bBb' , 'cCc' , 'dDd' ])
254
+ expected = expected if box == Index else Series (expected .values ,
255
+ index = s .values )
255
256
256
257
# Series/Index with DataFrame
257
258
result = s .str .cat (d )
258
- assert_series_or_index_equal (result , exp )
259
+ assert_series_or_index_equal (result , expected )
259
260
260
261
# Series/Index with two-dimensional ndarray
261
262
result = s .str .cat (d .values )
262
- assert_series_or_index_equal (result , exp )
263
+ assert_series_or_index_equal (result , expected )
263
264
264
265
# Series/Index with list of Series
265
266
result = s .str .cat ([t , s ])
266
- assert_series_or_index_equal (result , exp )
267
+ assert_series_or_index_equal (result , expected )
267
268
268
269
# Series/Index with mixed list of Series/array
269
270
result = s .str .cat ([t , s .values ])
270
- assert_series_or_index_equal (result , exp )
271
+ assert_series_or_index_equal (result , expected )
271
272
272
273
# Series/Index with list of list-likes
273
274
with tm .assert_produces_warning (expected_warning = FutureWarning ):
274
275
# nested list-likes will be deprecated
275
276
result = s .str .cat ([t .values , list (s )])
276
- assert_series_or_index_equal (result , exp )
277
+ assert_series_or_index_equal (result , expected )
277
278
278
279
# Series/Index with list of Series; different indexes
279
280
t .index = ['b' , 'c' , 'd' , 'a' ]
280
281
with tm .assert_produces_warning (expected_warning = FutureWarning ):
281
282
# FutureWarning to switch to alignment by default
282
283
result = s .str .cat ([t , s ])
283
- assert_series_or_index_equal (result , exp )
284
+ assert_series_or_index_equal (result , expected )
284
285
285
286
# Series/Index with mixed list; different indexes
286
287
with tm .assert_produces_warning (expected_warning = FutureWarning ):
287
288
# FutureWarning to switch to alignment by default
288
289
result = s .str .cat ([t , s .values ])
289
- assert_series_or_index_equal (result , exp )
290
+ assert_series_or_index_equal (result , expected )
290
291
291
292
# Series/Index with DataFrame; different indexes
292
293
d .index = ['b' , 'c' , 'd' , 'a' ]
293
294
with tm .assert_produces_warning (expected_warning = FutureWarning ):
294
295
# FutureWarning to switch to alignment by default
295
296
result = s .str .cat (d )
296
- assert_series_or_index_equal (result , exp )
297
+ assert_series_or_index_equal (result , expected )
297
298
298
299
# Series/Index with iterator of list-likes
299
300
with tm .assert_produces_warning (expected_warning = FutureWarning ):
300
301
# nested list-likes will be deprecated
301
302
result = s .str .cat (iter ([t .values , list (s )]))
302
- assert_series_or_index_equal (result , exp )
303
+ assert_series_or_index_equal (result , expected )
303
304
304
305
# errors for incorrect lengths
305
306
rgx = 'All arrays must be same length, except those having an index.*'
@@ -359,50 +360,50 @@ def test_str_cat_align_indexed(self, box, join):
359
360
t = Series (['D' , 'A' , 'E' , 'B' ], index = ['d' , 'a' , 'e' , 'b' ])
360
361
sa , ta = s .align (t , join = join )
361
362
# result after manual alignment of inputs
362
- exp = sa .str .cat (ta , na_rep = '-' )
363
+ expected = sa .str .cat (ta , na_rep = '-' )
363
364
364
365
if box == Index :
365
366
s = Index (s )
366
367
sa = Index (sa )
367
- exp = Index (exp )
368
+ expected = Index (expected )
368
369
369
370
result = s .str .cat (t , join = join , na_rep = '-' )
370
- assert_series_or_index_equal (result , exp )
371
+ assert_series_or_index_equal (result , expected )
371
372
372
373
@pytest .mark .parametrize ('join' , ['left' , 'outer' , 'inner' , 'right' ])
373
374
def test_str_cat_align_mixed_inputs (self , join ):
374
375
s = Series (['a' , 'b' , 'c' , 'd' ])
375
376
t = Series (['d' , 'a' , 'e' , 'b' ], index = [3 , 0 , 4 , 1 ])
376
377
d = concat ([t , t ], axis = 1 )
377
378
378
- exp_outer = Series (['aaa' , 'bbb' , 'c--' , 'ddd' , '-ee' ])
379
- exp = exp_outer .loc [s .index .join (t .index , how = join )]
379
+ expected_outer = Series (['aaa' , 'bbb' , 'c--' , 'ddd' , '-ee' ])
380
+ expected = expected_outer .loc [s .index .join (t .index , how = join )]
380
381
381
382
# list of Series
382
383
result = s .str .cat ([t , t ], join = join , na_rep = '-' )
383
- tm .assert_series_equal (result , exp )
384
+ tm .assert_series_equal (result , expected )
384
385
385
386
# DataFrame
386
387
result = s .str .cat (d , join = join , na_rep = '-' )
387
- tm .assert_series_equal (result , exp )
388
+ tm .assert_series_equal (result , expected )
388
389
389
390
# mixed list of indexed/unindexed
390
391
u = np .array (['A' , 'B' , 'C' , 'D' ])
391
- exp_outer = Series (['aaA' , 'bbB' , 'c-C' , 'ddD' , '-e-' ])
392
+ expected_outer = Series (['aaA' , 'bbB' , 'c-C' , 'ddD' , '-e-' ])
392
393
# joint index of rhs [t, u]; u will be forced have index of s
393
394
rhs_idx = t .index & s .index if join == 'inner' else t .index | s .index
394
395
395
- exp = exp_outer .loc [s .index .join (rhs_idx , how = join )]
396
+ expected = expected_outer .loc [s .index .join (rhs_idx , how = join )]
396
397
result = s .str .cat ([t , u ], join = join , na_rep = '-' )
397
- tm .assert_series_equal (result , exp )
398
+ tm .assert_series_equal (result , expected )
398
399
399
400
with tm .assert_produces_warning (expected_warning = FutureWarning ):
400
401
# nested list-likes will be deprecated
401
402
result = s .str .cat ([t , list (u )], join = join , na_rep = '-' )
402
- tm .assert_series_equal (result , exp )
403
+ tm .assert_series_equal (result , expected )
403
404
404
405
# errors for incorrect lengths
405
- rgx = 'If `others` contains arrays or lists \(or other list-likes.*'
406
+ rgx = r 'If `others` contains arrays or lists \(or other list-likes.*'
406
407
z = Series (['1' , '2' , '3' ]).values
407
408
408
409
# unindexed object of wrong length
@@ -418,14 +419,14 @@ def test_str_cat_special_cases(self):
418
419
t = Series (['d' , 'a' , 'e' , 'b' ], index = [3 , 0 , 4 , 1 ])
419
420
420
421
# iterator of elements with different types
421
- exp = Series (['aaa' , 'bbb' , 'c-c' , 'ddd' , '-e-' ])
422
+ expected = Series (['aaa' , 'bbb' , 'c-c' , 'ddd' , '-e-' ])
422
423
result = s .str .cat (iter ([t , s .values ]), join = 'outer' , na_rep = '-' )
423
- tm .assert_series_equal (result , exp )
424
+ tm .assert_series_equal (result , expected )
424
425
425
426
# right-align with different indexes in others
426
- exp = Series (['aa-' , 'd-d' ], index = [0 , 3 ])
427
+ expected = Series (['aa-' , 'd-d' ], index = [0 , 3 ])
427
428
result = s .str .cat ([t .loc [[0 ]], t .loc [[3 ]]], join = 'right' , na_rep = '-' )
428
- tm .assert_series_equal (result , exp )
429
+ tm .assert_series_equal (result , expected )
429
430
430
431
def test_cat_on_filtered_index (self ):
431
432
df = DataFrame (index = MultiIndex .from_product (
0 commit comments