@@ -377,13 +377,37 @@ def test_str_cat_align_mixed_inputs(self, join):
377
377
with tm .assert_raises_regex (ValueError , rgx ):
378
378
s .str .cat ([t , z ], join = join )
379
379
380
- def test_str_cat_raises (self ):
380
+ @pytest .mark .parametrize ('box' , [Series , Index ])
381
+ def test_str_cat_raises (self , box ):
381
382
# non-strings hiding behind object dtype
382
- s = Series ([1 , 2 , 3 , 4 ], dtype = 'object' )
383
+ s = box ([1 , 2 , 3 , 4 ], dtype = 'object' )
383
384
message = 'Can only use .str accessor with string values'
384
385
with tm .assert_raises_regex (AttributeError , message ):
385
386
s .str
386
387
388
+ @pytest .mark .parametrize ('box' , [Series , Index ])
389
+ @pytest .mark .parametrize ('other' , [Series , Index ])
390
+ def test_str_cat_all_na (self , box , other ):
391
+ # check that all NaNs in caller / target work
392
+ s = Index (['a' , 'b' , 'c' , 'd' ])
393
+ s = s if box == Index else Series (s , index = s )
394
+ t = other ([np .nan ] * 4 , dtype = 'object' )
395
+ # add index of s for alignment
396
+ t = t if other == Index else Series (t , index = s )
397
+
398
+ # all-NA target
399
+ expected = Index ([np .nan ] * 4 , dtype = 'object' )
400
+ expected = expected if box == Index else Series (expected ,
401
+ index = s .index )
402
+ result = s .str .cat (t , join = 'left' )
403
+ assert_series_or_index_equal (result , expected )
404
+
405
+ # all-NA caller (only for Series)
406
+ if other == Series :
407
+ expected = Series ([np .nan ] * 4 , dtype = 'object' , index = t .index )
408
+ result = t .str .cat (s , join = 'left' )
409
+ tm .assert_series_equal (result , expected )
410
+
387
411
def test_str_cat_special_cases (self ):
388
412
s = Series (['a' , 'b' , 'c' , 'd' ])
389
413
t = Series (['d' , 'a' , 'e' , 'b' ], index = [3 , 0 , 4 , 1 ])
0 commit comments