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: Addition raises TypeError if Period is on rhs #13069

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented May 3, 2016

  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

Period addition raises TypeError if Period is on right hand side.

1 + pd.Period('2011-01', freq='M')
# TypeError: unsupported operand type(s) for +: 'int' and 'pandas._period.Period'

Expected

1 + pd.Period('2011-01', freq='M')
# Period('2011-02', 'M')

@sinhrks sinhrks added Bug Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type labels May 3, 2016
@sinhrks sinhrks added this to the 0.18.2 milestone May 3, 2016
@jreback
Copy link
Contributor

jreback commented May 3, 2016

didn't you make this an issue somewhere? (or maybe just a comment)

if isinstance(other, (ABCDatetimeIndex, ABCSeries)):
return other + self
elif isinstance(other, Period):
Copy link
Contributor

Choose a reason for hiding this comment

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

can use ABCPeriod

@sinhrks
Copy link
Member Author

sinhrks commented May 3, 2016

No existing issue. Updated the top comment.

"""

def __radd__(self, other):
# __radd__ on cython extension types like _Period is not used, so
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reference somewhere on this? just curious

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find as long as I searched. We can fix Timestamp if there is a workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

on what I mean is where you saw that it didn't work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Once I tried to add __radd__ to cdef Period and found it doesn't work. Then noticed _Timestamp impl. I'm not sure where _Timestamp impl derived from.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh so this means you can leave Period and we don't need _Period. That's only necessary for Timestamp for example because we are extending a c class itself
here the class is already in cython

but what it does mean is that add needs to handle reversed args directly (and similarly for other arith ops)

Copy link
Member Author

Choose a reason for hiding this comment

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

I read the doc something like below. This looks work removing _Period class.

   def __add__(self, other):
       if isinstance(self, Period):
           ...
       elif isinstance(other, Period):
           return other + self
       else:
           ...

@sinhrks sinhrks force-pushed the period_radd branch 3 times, most recently from 0d31d32 to cdcd3b3 Compare May 5, 2016 23:20
@codecov-io
Copy link

codecov-io commented May 6, 2016

Current coverage is 84.14%

Merging #13069 into master will increase coverage by +<.01%

@@             master     #13069   diff @@
==========================================
  Files           137        137          
  Lines         50261      50231    -30   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          42288      42265    -23   
+ Misses         7973       7966     -7   
  Partials          0          0          
  1. 2 files (not in diff) in pandas/tseries were modified. more
    • Misses -4
    • Hits -22
  2. 2 files (not in diff) in pandas were modified. more
    • Misses -3
    • Hits -5

Powered by Codecov. Last updated by 1296ab3...cdcd3b3

BUG: Addition raises TypeError if Period is on rhs
@jreback
Copy link
Contributor

jreback commented May 7, 2016

thanks @sinhrks

@sinhrks sinhrks deleted the period_radd branch May 7, 2016 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants