Skip to content

Commit 191d18d

Browse files
committed
Merge pull request #7902 from toobaz/_get_array_list
BUG: do not assume 0 is in index of potential Series
2 parents 7705027 + 1ea91ce commit 191d18d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

doc/source/v0.15.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ Bug Fixes
343343
date-likes incorrectly (:issue:`7762`, :issue:`7032`).
344344

345345

346+
- Bug in ``Series.str.cat`` with an index which was filtered as to not include the first item (:issue:`7857`)
346347

347348

348349

pandas/core/strings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313

1414
def _get_array_list(arr, others):
15-
if len(others) and isinstance(others[0], (list, np.ndarray)):
15+
if len(others) and isinstance(_values_from_object(others)[0],
16+
(list, np.ndarray, Series)):
1617
arrays = [arr] + list(others)
1718
else:
1819
arrays = [arr, others]

pandas/tests/test_strings.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pandas.compat import range, lrange, u
1717
import pandas.compat as compat
1818
from pandas import (Index, Series, TimeSeries, DataFrame, isnull, notnull,
19-
bdate_range, date_range)
19+
bdate_range, date_range, MultiIndex)
2020
import pandas.core.common as com
2121

2222
from pandas.util.testing import assert_series_equal, assert_almost_equal
@@ -1193,6 +1193,23 @@ def test_encode_decode_errors(self):
11931193

11941194
tm.assert_series_equal(result, exp)
11951195

1196+
def test_cat_on_filtered_index(self):
1197+
df = DataFrame(index=MultiIndex.from_product([[2011, 2012], [1,2,3]],
1198+
names=['year', 'month']))
1199+
1200+
df = df.reset_index()
1201+
df = df[df.month > 1]
1202+
1203+
str_year = df.year.astype('str')
1204+
str_month = df.month.astype('str')
1205+
str_both = str_year.str.cat(str_month, sep=' ')
1206+
1207+
self.assertEqual(str_both.loc[1], '2011 2')
1208+
1209+
str_multiple = str_year.str.cat([str_month, str_month], sep=' ')
1210+
1211+
self.assertEqual(str_multiple.loc[1], '2011 2 2')
1212+
11961213

11971214
if __name__ == '__main__':
11981215
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)