Skip to content
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/API: Series arithmetic ops inconsistently hold names #10068

Closed
sinhrks opened this issue May 6, 2015 · 6 comments · Fixed by #10240
Closed

BUG/API: Series arithmetic ops inconsistently hold names #10068

sinhrks opened this issue May 6, 2015 · 6 comments · Fixed by #10240
Labels
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented May 6, 2015

Based on Index behavior, Series arithmetic should reset name when names are different?

import pandas as pd
s1 = pd.Series([1, 2, 3], name='a')
s2 = pd.Series([3, 4, 5], name='b')

(s1 + s2).name
# None

s1.add(s2).name
# a
@sinhrks sinhrks added the Bug label May 6, 2015
@jreback
Copy link
Contributor

jreback commented May 6, 2015

This looks like just need to pass name to the constructor https://github.com/pydata/pandas/blob/master/pandas/core/series.py#L1510

@jreback jreback added this to the Next Major Release milestone May 6, 2015
@vikramls
Copy link

The fix is in ops.py - https://github.com/pydata/pandas/blob/master/pandas/core/ops.py#L509 - I added a check for if name is None and used the name from left if this is True. This however breaks an explicit test - https://github.com/pydata/pandas/blob/master/pandas/tests/test_series.py#L266. If the names don't match, neither is selected. Should I update this test as part of the fix as well?

@shoyer
Copy link
Member

shoyer commented May 11, 2015

@vikramls I don't think we want to change that behavior (if names are different, the resulting name should be None). So I guess this needs a different fix.

@vikramls
Copy link

@shoyer - The test-case checks the same scenario that this bug is addressed to. Does this mean that the bug is not valid?

from test_series.py:

    result = self.ts + cp # self.ts and cp are both Series objects
    self.assertIsNone(result.name)

Series.add is executed via the _binop method wheres Series + Series is executed via the added __add__ method.

@shoyer
Copy link
Member

shoyer commented May 11, 2015

@vikramls To clarify, I think this behavior is correct:

(s1 + s2).name
# None

and this behavior is the bug:

s1.add(s2).name
# a

@vikramls
Copy link

@shoyer, thanks for the clarification. In this case the bug is triggered by the call to __finalize__ which copies attributes from other to the newly created object. One fix is to remove the call to __finalize__ in _binop but it doesn't seem right to special-case _binop in this manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants