-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
BUG: Should not raise error in concatenating Series with numpy scalar and tuple names (GH21015) #21132
Changes from 4 commits
13f00df
354eb2d
613ab4e
3e84f9c
35b664f
7ec0135
345c084
21d834e
ba8abba
8aa7e05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,10 @@ def flatten(l): | |
def _consensus_name_attr(objs): | ||
name = objs[0].name | ||
for obj in objs[1:]: | ||
if obj.name != name: | ||
try: | ||
if obj.name != name: | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback Thanks - will make the changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
except ValueError: | ||
return None | ||
return name | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2350,6 +2350,21 @@ def test_concat_datetime_timezone(self): | |
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_concat_series_name_npscalar_tuple(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parameterize this on a np.int64 and an int There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double backticks around Series, is this only a numpy scalar or any scalar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only numpy scalar - as it returns an array on comparison with tuple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok that's fine (but add in an integer in the test as well below)