Skip to content

Commit e80cc43

Browse files
KalyanGokhalejreback
authored andcommitted
BUG: Should not raise error in concatenating Series with numpy scalar and tuple names (GH21015) (#21132)
1 parent 3cae0a2 commit e80cc43

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

doc/source/whatsnew/v0.23.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Plotting
8787
Reshaping
8888
^^^^^^^^^
8989

90-
-
90+
- Bug in :func:`concat` where error was raised in concatenating :class:`Series` with numpy scalar and tuple names (:issue:`21015`)
9191
-
9292

9393
Categorical

pandas/core/common.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ def flatten(l):
5555
def _consensus_name_attr(objs):
5656
name = objs[0].name
5757
for obj in objs[1:]:
58-
if obj.name != name:
59-
return None
58+
try:
59+
if obj.name != name:
60+
name = None
61+
except ValueError:
62+
name = None
6063
return name
6164

6265

pandas/tests/reshape/test_concat.py

+11
Original file line numberDiff line numberDiff line change
@@ -2487,3 +2487,14 @@ def test_concat_aligned_sort_does_not_raise():
24872487
columns=[1, 'a'])
24882488
result = pd.concat([df, df], ignore_index=True, sort=True)
24892489
tm.assert_frame_equal(result, expected)
2490+
2491+
2492+
@pytest.mark.parametrize("s1name,s2name", [
2493+
(np.int64(190), (43, 0)), (190, (43, 0))])
2494+
def test_concat_series_name_npscalar_tuple(s1name, s2name):
2495+
# GH21015
2496+
s1 = pd.Series({'a': 1, 'b': 2}, name=s1name)
2497+
s2 = pd.Series({'c': 5, 'd': 6}, name=s2name)
2498+
result = pd.concat([s1, s2])
2499+
expected = pd.Series({'a': 1, 'b': 2, 'c': 5, 'd': 6})
2500+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)