Skip to content

ERR: clarify exceptions for invalid datetimelike ops #9631

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
jreback opened this issue Mar 11, 2015 · 5 comments · Fixed by #17772
Closed

ERR: clarify exceptions for invalid datetimelike ops #9631

jreback opened this issue Mar 11, 2015 · 5 comments · Fixed by #17772
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Mar 11, 2015

xref #9630

IIRC most of these are TypeErrors (see tseries/tests_base.py, section on addition/subtraction ops)
but I guess some are`NotImplementedError``

In [3]: pd.date_range('20130101',periods=5)+Timestamp('20140101')
NotImplementedError: 
In [4]: pd.date_range('20130101',periods=5)+Timestamp('20140101').to_datetime64()

TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]')
@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Mar 11, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 11, 2015
@jreback jreback modified the milestones: 0.17.0, 0.16.1 Apr 21, 2015
@jreback jreback modified the milestones: 0.17.0, Next Major Release Aug 15, 2015
@mturzanska
Copy link
Contributor

@jreback looks like a good first issue. Would like to work on this one over the next weekend. Are there any blockers / anyone already working on this one?

@jreback
Copy link
Contributor Author

jreback commented Sep 25, 2017

go for it!

@mturzanska
Copy link
Contributor

To clarify, based on the discussion from #9630, all NotImplementedErrors should be caught and replaced with TypeError
Is it correct?

@jreback
Copy link
Contributor Author

jreback commented Oct 1, 2017

actually that example looks fixed:

In [1]: pd.date_range('20130101',periods=5)+Timestamp('20140101')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-4fbfb506deba> in <module>()
----> 1 pd.date_range('20130101',periods=5)+Timestamp('20140101')

/Users/jreback/pandas/pandas/core/indexes/datetimelike.py in __add__(self, other)
    658                 return self.shift(other)
    659             elif isinstance(other, (Timestamp, datetime)):
--> 660                 return self._add_datelike(other)
    661             else:  # pragma: no cover
    662                 return NotImplemented

/Users/jreback/pandas/pandas/core/indexes/datetimes.py in _add_datelike(self, other)
    748         if other is libts.NaT:
    749             return self._nat_new(box=True)
--> 750         raise TypeError("cannot add a datelike to a DatetimeIndex")
    751 
    752     def _sub_datelike(self, other):

TypeError: cannot add a datelike to a DatetimeIndex

but

In [2]: pd.date_range('20130101',periods=5)+Timestamp('20140101').to_datetime64()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-f97a2c790501> in <module>()
----> 1 pd.date_range('20130101',periods=5)+Timestamp('20140101').to_datetime64()

TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]')

should be a 'better' error message (the TypeError is ok)

@jreback
Copy link
Contributor Author

jreback commented Oct 1, 2017

basically the path for [2] should end up similarly to [1]

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants