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.timedelta64 integer coercion in older numpy #19807

Closed
jbrockmendel opened this issue Feb 21, 2018 · 2 comments
Closed

np.timedelta64 integer coercion in older numpy #19807

jbrockmendel opened this issue Feb 21, 2018 · 2 comments

Comments

@jbrockmendel
Copy link
Member

Ref #19333

In sufficiently old numpy (the build that caught this bug was running 1.9.2) timedelta64 comparisons have unexpected behavior:

value = np.timedelta64(1, 'ns')
new_value = int(value)
assert value == new_value   # <-- raises with modern numpy, passes with older versions

This particular comparison is done in the RangeIndex constructor, the result being that sometimesRangeIndex(value, value*10, value) returns RangeIndex(1, 10, 1) instead of raising.

The immediate problem can be fixed by checking more carefully in the RangeIndex constructor. No idea if there are other places that are affected.


A related behavior that I find unhelpful that is present with 1.14.1 is:

>>> td = pd.Timedelta(days=1).to_timedelta64()
>>> pd._libs.lib.is_integer(td)
True
@jreback
Copy link
Contributor

jreback commented Feb 21, 2018

what is the purpose of opening a separate issue for this? this is a well known detail of how np.timedelta64 are implemented. which is True for all numpies (the 2nd part)

@jreback jreback closed this as completed Feb 21, 2018
@jbrockmendel
Copy link
Member Author

The purpose is to address the behavior. The #19333 addresses one effect of this behavior, but does not fix it, doesn't even fix RangeIndex.__new__

As for the second part, lib.is_integer is part of pandas. If we want it to behave in a more reasonable way, that's easy to make happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants