Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ Reshaping
^^^^^^^^^

- Bug in :func:`pandas.concat` when joining resampled DataFrames with timezone aware index (:issue:`13783`)
- Bug in :func:`pandas.concat` when joining only `Series` the `names` argument of `concat` is no longer ignored (:issue:`23490`)
- Bug in :meth:`Series.combine_first` with ``datetime64[ns, tz]`` dtype which would return tz-naive result (:issue:`21469`)
- Bug in :meth:`Series.where` and :meth:`DataFrame.where` with ``datetime64[ns, tz]`` dtype (:issue:`21546`)
- Bug in :meth:`Series.mask` and :meth:`DataFrame.mask` with ``list`` conditionals (:issue:`21891`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def _get_concat_axis(self):
else:
return ibase.default_index(len(self.objs))
else:
return ensure_index(self.keys)
return ensure_index(self.keys).set_names(self.names)
else:
indexes = [x._data.axes[self.axis] for x in self.objs]

Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,23 @@ def test_concat_series_axis1(self, sort=sort):
expected = DataFrame({'A': s, 'B': s2})
assert_frame_equal(result, expected)

def test_concat_series_axis1_names_applied(self):
# ensure names argument is not ignored on axis=1, #23490
s = Series([1, 2, 3])
s2 = Series([4, 5, 6])
result = concat([s, s2], axis=1, keys=['a', 'b'], names=['A'])
expected = DataFrame([[1, 4], [2, 5], [3, 6]],
columns=pd.Index(['a', 'b'], name='A'))
assert_frame_equal(result, expected)

result = concat([s, s2], axis=1, keys=[('a', 1), ('b', 2)],
names=['A', 'B'])
expected = DataFrame([[1, 4], [2, 5], [3, 6]],
columns=MultiIndex.from_tuples([('a', 1),
('b', 2)],
names=['A', 'B']))
assert_frame_equal(result, expected)

def test_concat_single_with_key(self):
df = DataFrame(np.random.randn(10, 4))

Expand Down