Skip to content

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

Closed
@jtratner

Description

@jtratner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasNumeric OperationsArithmetic, Comparison, and Logical operationsPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions