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

np.ndarray[object] - Timedelta raises #21980

Closed
jbrockmendel opened this issue Jul 19, 2018 · 10 comments

Comments

Projects
None yet
4 participants
@jbrockmendel
Copy link
Member

commented Jul 19, 2018

arr = np.array([pd.Timestamp.now(), pd.Timedelta('2D')])

>>> arr - pd.Timedelta('1D')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'Timedelta'

It should attempt to operate element-wise.

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Jul 20, 2018

I suppose this is because of

elif hasattr(other, 'dtype'):
# nd-array like
if other.dtype.kind not in ['m', 'M']:
# raise rathering than letting numpy return wrong answer
return NotImplemented
return op(self.to_timedelta64(), other)

Any idea what the "wrong" answer would be? (with timedelta.timedelta instead of Timedelta that seems to work just fine, so I assume with Timedelta it will be the same)

@jbrockmendel

This comment has been minimized.

Copy link
Member Author

commented Jul 20, 2018

No idea what the wrong answer would be. This should be easy to fix; if no one else picks it up I'll take care of it once the current PR queue settles down.

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Jul 20, 2018

Yes, PR with a fix is certainly welcome I think

@illegalnumbers

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2018

Is this still an issue? I wasn't able to repro from master.

@jbrockmendel

This comment has been minimized.

Copy link
Member Author

commented Jul 24, 2018

Is this still an issue? I wasn't able to repro from master.

What platform etc? I still get it on OSX in both py27 and py37.

@illegalnumbers

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2018

OSX 10.11.6 with Python 3.6. I just pulled up a REPL and imported pandas from a compile I did yesterday from master and didn't get an exception from the example code posted. Specifically Python 3.6.6 (default, Jul 23 2018, 11:08:18) [GCC 4.2.1 Compatible Clang 6.0.0 (tags/RELEASE_600/final)] on darwin

@illegalnumbers

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2018

I also didn't see the issue from the latest install from pip either. Both times I just got

>>> arr = np.array([pd.Timestamp.now(), pd.Timedelta('2D')])
>>> arr
array([Timestamp('2018-07-24 10:49:41.898067'),
       Timedelta('2 days 00:00:00')], dtype=object)
@jbrockmendel

This comment has been minimized.

Copy link
Member Author

commented Jul 24, 2018

Did you try subtracting a Timedelta from arr?

@illegalnumbers

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2018

Ah! 🤦‍♂️ yea I missed that part in the example. I repro'd the bug with that on master and latest pip. So with this then how should I go about the fix? It's not operating element wise on the array because the timedeltas.pyx isn't returning that it is a timedelta correctly? or...?

@jbrockmendel

This comment has been minimized.

Copy link
Member Author

commented Jul 24, 2018

how should I go about the fix?

Take a look at the code block Joris quoted above. At the moment that lets 'm' and 'M' dtypes through but stops everything else. The fix will involve letting 'o' dtypes through (and making sure they are handled correctly)

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 25, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 25, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 25, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 25, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Jul 26, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Aug 17, 2018

@jreback jreback added this to the 0.24.0 milestone Aug 20, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Aug 23, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Sep 4, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Sep 5, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Sep 5, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Sep 6, 2018

illegalnumbers added a commit to illegalnumbers/pandas that referenced this issue Sep 13, 2018

jreback added a commit that referenced this issue Sep 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.