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

Conversation

KalyanGokhale
Copy link
Contributor

@KalyanGokhale KalyanGokhale commented May 19, 2018

Does not raise error in concatting Series with numpy scalar and tuple names
Does not raise error in concatting Series with numpy scalar and tuple names
@codecov
Copy link

codecov bot commented May 19, 2018

Codecov Report

Merging #21132 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.23% <100%> (ø) ⬆️
#single 41.88% <40%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/common.py 92.09% <100%> (+0.08%) ⬆️
pandas/core/reshape/reshape.py 99.78% <0%> (-0.22%) ⬇️
pandas/core/frame.py 97.23% <0%> (ø) ⬆️
pandas/util/testing.py 84.81% <0%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e033c06...8aa7e05. Read the comment docs.

Changed to negative test for bool or np.bool_
Copy link
Member

@WillAyd WillAyd left a 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?

@@ -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

@WillAyd WillAyd added the Bug label May 19, 2018
@WillAyd WillAyd added this to the 0.23.1 milestone May 19, 2018
Changed to try except block, instead of type introspection
if obj.name != name:
try:
if obj.name != name:
return None
Copy link
Contributor

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

Copy link
Contributor Author

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

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

@@ -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
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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)

@@ -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)

@@ -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.

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

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

@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label May 19, 2018
made changes suggested by @jreback on 19May
made changes suggested by @jreback on 19May
Copy link
Member

@WillAyd WillAyd left a 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

@@ -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



@pytest.mark.parametrize("s1name, s2name", [(np.int64(190), (43, 0)),
(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

made minor style changes to test file suggested by @WillAyd
made minor style changes to test file suggested by @WillAyd


@pytest.mark.parametrize("s1name,s2name", [
(np.int64(190), (43, 0)), (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.

The open bracket is correct but the line below is now over-indented - make sure you set that back accordingly

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 - sorry for so many iterations

@@ -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

made minor style changes to whatsnew file suggested by @WillAyd
made minor style changes to test file suggested by @WillAyd
@jreback jreback merged commit e80cc43 into pandas-dev:master May 21, 2018
@jreback
Copy link
Contributor

jreback commented May 21, 2018

thanks @KalyanGokhale

@KalyanGokhale KalyanGokhale deleted the concat-series branch May 21, 2018 12:01
jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jun 8, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jun 9, 2018
… and tuple names (GH21015) (#21132)

(cherry picked from commit e80cc43)
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: error in concatting Series with numpy scalar / tuple names
4 participants