Skip to content

BUG: Should not raise error in concatenating Series with numpy scalar and tuple names (GH21015) #21132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Plotting
Reshaping
^^^^^^^^^

-
- Bug in :func:`concat` where error was raised in concatenating ``Series`` with numpy scalar and tuple names (:issue:`21015`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace ``Series`` with :class:`Series`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

-

Categorical
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def flatten(l):
def _consensus_name_attr(objs):
name = objs[0].name
for obj in objs[1:]:
if obj.name != name:
return None
try:
if obj.name != name:
name = None
except ValueError:
name = None
return name


Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2487,3 +2487,14 @@ def test_concat_aligned_sort_does_not_raise():
columns=[1, 'a'])
result = pd.concat([df, df], ignore_index=True, sort=True)
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("s1name, s2name", [(np.int64(190), (43, 0)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space between s1name and s2name here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

(190, (43, 0))])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably push the tuple on the above line down here - would make the indentation more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thanks

def test_concat_series_name_npscalar_tuple(s1name, s2name):
# GH21015
s1 = pd.Series({'a': 1, 'b': 2}, name=s1name)
s2 = pd.Series({'c': 5, 'd': 6}, name=s2name)
result = pd.concat([s1, s2])
expected = pd.Series({'a': 1, 'b': 2, 'c': 5, 'd': 6})
tm.assert_series_equal(result, expected)