-
-
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21132 +/- ##
==========================================
+ Coverage 91.83% 91.84% +<.01%
==========================================
Files 153 153
Lines 49498 49502 +4
==========================================
+ Hits 45458 45463 +5
+ Misses 4040 4039 -1
Continue to review full report at Codecov.
|
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.
Thanks for the PR! Comments below - can you also add a whatsnew note?
pandas/core/common.py
Outdated
@@ -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_)): |
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.
Can you use a try...except block here to catch the ValueError instead of type introspection?
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.
@WillAyd thanks - will make the changes. Should I add whatsnew note to v0.23.1?
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.
Yes that works
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.
Done
pandas/core/common.py
Outdated
if obj.name != name: | ||
try: | ||
if obj.name != name: | ||
return None |
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.
do like
try:
if obj.name != name:
name = None
except ValueError:
name = None
return name
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.
@jreback Thanks - will make the changes
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.
done
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -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`) |
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)
pandas/tests/reshape/test_concat.py
Outdated
@@ -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 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)
pandas/tests/reshape/test_concat.py
Outdated
@@ -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 comment
The 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 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
pandas/tests/reshape/test_concat.py
Outdated
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 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.
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.
will update - had added the original test case from the issue #21015
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.
Very minor style nits but otherwise lgtm
pandas/tests/reshape/test_concat.py
Outdated
@@ -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)), |
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.
No space between s1name
and s2name
here
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.
done
pandas/tests/reshape/test_concat.py
Outdated
|
||
|
||
@pytest.mark.parametrize("s1name, s2name", [(np.int64(190), (43, 0)), | ||
(190, (43, 0))]) |
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.
Could probably push the tuple on the above line down here - would make the indentation more readable
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.
done. Thanks
pandas/tests/reshape/test_concat.py
Outdated
|
||
|
||
@pytest.mark.parametrize("s1name,s2name", [ | ||
(np.int64(190), (43, 0)), (190, (43, 0))]) |
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.
The open bracket is correct but the line below is now over-indented - make sure you set that back accordingly
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.
done - sorry for so many iterations
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -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`) |
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.
Let's replace ``Series`` with :class:`Series`
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.
done
thanks @KalyanGokhale |
… and tuple names (GH21015) (pandas-dev#21132) (cherry picked from commit e80cc43)
… and tuple names (GH21015) (pandas-dev#21132)
git diff upstream/master -u -- "*.py" | flake8 --diff