Skip to content

isin doesn't work for Timestamps #5021

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
cpcloud opened this issue Sep 28, 2013 · 15 comments · Fixed by #5303
Closed

isin doesn't work for Timestamps #5021

cpcloud opened this issue Sep 28, 2013 · 15 comments · Fixed by #5303
Labels
Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Sep 28, 2013

SO question: http://stackoverflow.com/q/19070194/564538

@dsm054
Copy link
Contributor

dsm054 commented Oct 23, 2013

This just came up again: http://stackoverflow.com/questions/19551336/using-isin-with

Options:

(1) Raise. Irritating but no one will get the wrong answer.

(2) Detect common cases like timestamps which don't place nicely with hashes and do list membership testing instead of set membership testing. Slow for big collections but it'll give the right answer, and probably work well enough in the typical case of a small group.

(2b) Instead of list membership testing, sort and then bisect if the to-be-tested collection is big enough.

(3) Make sure that standard time objects have compatible hashes.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

@dsm054 thanks for the ping on this.....pretty easy to fix actually....just need to convert to i8 for date/time like inputs and it works with the existing methods

@dsm054
Copy link
Contributor

dsm054 commented Oct 23, 2013

Does that preserve precision? When I ran the idea of coercing to a common type past @cpcloud, he seemed sceptical.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

yep....this is what we do with date/time-likes....the in64's are in nanoseconds

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

it doesn't use the __hash__ of the actual objects, rather the hashes of the integers which back the date/time-like (which prob hash to themselves)

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

@dsm054 do you have any more tests that you think I ought to include?

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

Do python datetimes hash to their integer value? The ts class does use the object hash if there are no nanoseconds which I would assume constitutes the majority of use cases.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

it doesn't matter in this case, as everything hashes as the value which is the num of nanoseconds in epoch space

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

Ah ok nice

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

right I saw ur pr. Just convert to int b4 hand

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

Maybe test that an ndarray and series as an arg to isin return the same result

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

Ndarray with datetime64 style that is

@cpcloud
Copy link
Member Author

cpcloud commented Oct 23, 2013

Dtype I meant

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

ok...sure

@jreback
Copy link
Contributor

jreback commented Oct 24, 2013

works just fine (because to_datetime which does conversions on the input works on these :)

In [3]: s[0:2].values
Out[3]: 
array(['2012-12-31T19:00:00.000000000-0500',
       '2013-01-01T19:00:00.000000000-0500'], dtype='datetime64[ns]')

In [4]: s[0:2].values.astype('datetime64[D]')
Out[4]: array(['2013-01-01', '2013-01-02'], dtype='datetime64[D]')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants