Skip to content

ENH: return NotImplemented rather than raise TypeError in Period arithmetic. #4731

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

Closed
jtratner opened this issue Sep 1, 2013 · 0 comments · Fixed by #7485
Closed

ENH: return NotImplemented rather than raise TypeError in Period arithmetic. #4731

jtratner opened this issue Sep 1, 2013 · 0 comments · Fixed by #7485
Labels
Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type
Milestone

Comments

@jtratner
Copy link
Contributor

jtratner commented Sep 1, 2013

Right now, some of the error messages for in pandas/tseries/period.py are not so great:

In [9]: period = Period('2000-01-03', 'B')

In [10]: period > 1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-df287da31a9f> in <module>()
----> 1 period > 1

/pandas/tseries/period.pyc in f(self, other)
    172                 return func(self.ordinal, other.ordinal)
    173             else:
--> 174                 raise TypeError(other)
    175
    176         f.__name__ = name

TypeError: 1

And in the case above, should really return NotImplemented instead (so that they end up with an error message like):

----> 1 1 + period

TypeError: unsupported operand type(s) for +: 'int' and 'Period'

Side note - that's only appropriate these are only used as magic methods (so that the Python interpreter converts them into the TypeError shown above...).

@jreback jreback closed this as completed Jan 3, 2014
@jreback jreback reopened this Jan 3, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 11, 2014
@jreback jreback modified the milestones: 0.14.1, 0.15.0 Jun 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants