Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def flatten(l):
def _consensus_name_attr(objs):
name = objs[0].name
for obj in objs[1:]:
if obj.name != name:
name_check = (obj.name != name)
if not isinstance(name_check, (bool, np.bool_)):
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a try...except block here to catch the ValueError instead of type introspection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd thanks - will make the changes. Should I add whatsnew note to v0.23.1?

Copy link
Member

Choose a reason for hiding this comment

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

Yes that works

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

# 'If' test can also be a positive for 'np.ndarray'
return None
elif name_check:
return None
return name

Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,21 @@ def test_concat_datetime_timezone(self):

tm.assert_frame_equal(result, expected)

def test_concat_series_name_npscalar_tuple(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't need to be in the class, it can just be a module level test (e.g. de-dent)

Copy link
Contributor

Choose a reason for hiding this comment

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

parameterize this on a np.int64 and an int

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 - took the test out of class, parameterised as suggested, also actually removed the test case which took a row from DataFrame

# GH21015
s1 = pd.Series({'a': 1.5}, name=np.int64(190))
s2 = pd.Series([], name=(43, 0))
result = pd.concat([s1, s2])
expected = pd.Series({'a': 1.5})
tm.assert_series_equal(result, expected)

df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'], index=[0, 1])
Copy link
Contributor

Choose a reason for hiding this comment

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

this is very weird to construct a DataFrame to then take a row from it. Just directly construct the 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.

will update - had added the original test case from the issue #21015

df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['c', 'd'],
index=pd.MultiIndex.from_tuples([(0, 0), (1, 1)]))
result = pd.concat([df1.iloc[0], df2.iloc[0]])
expected = pd.Series({'a': 1, 'b': 2, 'c': 5, 'd': 6})
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame, pd.Panel])
@pytest.mark.parametrize('dt', np.sctypes['float'])
Expand Down