35
35
_shared_docs = dict ()
36
36
37
37
38
- def _get_array_list (arr , others ):
38
+ def _get_array_list (arr , others , align = True ):
39
39
from pandas .core .series import Series
40
-
41
- if len (others ) and isinstance (com ._values_from_object (others )[0 ],
40
+
41
+ if (len (arr ) and isinstance (arr , Series )
42
+ and len (others ) and isinstance (others , Series )):
43
+ if align is None :
44
+ align = False
45
+ warnings .warn ("A future version of pandas will perform alignment "
46
+ "when others is a series. To disable alignment (the "
47
+ "previous behavior) and silence this warning, pass "
48
+ "'align=False'. To enable alignment (the future "
49
+ "behavior) and silence this warning, pass "
50
+ "'align=True'" )
51
+ if align :
52
+ arr , others = arr .align (others , join = 'left' )
53
+ arrays = [list (arr ), list (others )]
54
+ elif len (others ) and isinstance (com ._values_from_object (others )[0 ],
42
55
(list , np .ndarray , Series )):
43
56
arrays = [arr ] + list (others )
44
57
else :
@@ -47,7 +60,7 @@ def _get_array_list(arr, others):
47
60
return [np .asarray (x , dtype = object ) for x in arrays ]
48
61
49
62
50
- def str_cat (arr , others = None , sep = None , na_rep = None ):
63
+ def str_cat (arr , others = None , sep = None , na_rep = None , align = None ):
51
64
"""
52
65
Concatenate strings in the Series/Index with given separator.
53
66
@@ -109,7 +122,7 @@ def str_cat(arr, others=None, sep=None, na_rep=None):
109
122
sep = ''
110
123
111
124
if others is not None :
112
- arrays = _get_array_list (arr , others )
125
+ arrays = _get_array_list (arr , others , align = align )
113
126
114
127
n = _length_check (arrays )
115
128
masks = np .array ([isna (x ) for x in arrays ])
@@ -1737,9 +1750,10 @@ def cons_row(x):
1737
1750
return cons (result , name = name , index = index )
1738
1751
1739
1752
@copy (str_cat )
1740
- def cat (self , others = None , sep = None , na_rep = None ):
1753
+ def cat (self , others = None , sep = None , na_rep = None , align = None ):
1741
1754
data = self ._orig if self ._is_categorical else self ._data
1742
- result = str_cat (data , others = others , sep = sep , na_rep = na_rep )
1755
+ result = str_cat (data , others = others , sep = sep ,
1756
+ na_rep = na_rep , align = align )
1743
1757
return self ._wrap_result (result , use_codes = (not self ._is_categorical ))
1744
1758
1745
1759
@copy (str_split )
0 commit comments