-
Notifications
You must be signed in to change notification settings - Fork 915
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
Cleanup some timedelta/datetime column logic #14715
Cleanup some timedelta/datetime column logic #14715
Conversation
def __contains__(self, item: ScalarLike) -> bool: | ||
try: | ||
item_as_dt64 = np.datetime64(item, self._time_unit) | ||
item_as_dt64 = np.datetime64(item, self.time_unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit If self.dtype
is a DatetimeTZDtype
is this code correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find, no it doesn't. In pandas least for DatetimeTZDtype
, item
must be tz-aware and the same UTC time to return True.
In [1]: import pandas as pd
In [2]: dti = pd.date_range("2020", periods=3, tz="UTC")
In [3]: pd.Timestamp("2020") in dti
Out[3]: False
In [4]: pd.Timestamp("2020", tz="UTC") in dti
Out[4]: True
In [5]: pd.Timestamp("2020", tz="US/Pacific") in dti
Out[5]: False
In [6]: pd.Timestamp("2019-12-31T16:00:00", tz="US/Pacific") in dti
Out[6]: True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this case and added a unit test
@wence- could you take another look at this PR? |
@wence- when you have a moment could you re-review this PR? |
… into ref/column/cleanups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some really nice cleanups here. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/merge |
Description
Remove private
_time_unit
attribute in favor of the public one and perform dtype validation earlier in__init__
Checklist