-
-
Notifications
You must be signed in to change notification settings - Fork 141
TYP: Add DatetimeIndex.intersection() method and test #745
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
Conversation
@@ -97,6 +97,7 @@ class DatetimeIndex( # type: ignore[misc] | |||
def tzinfo(self) -> tzinfo | None: ... | |||
@property | |||
def dtype(self) -> np.dtype | DatetimeTZDtype: ... | |||
def intersection(self, other: DatetimeIndex | list) -> DatetimeIndex: ... |
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.
list
is too broad. I think Sequence[DatetimeLike]
will work where you import DatetimeLike
from pandas._typing
|
||
result = idx1.intersection(idx2) | ||
|
||
check(assert_type(result, pd.DatetimeIndex), pd.DatetimeIndex) |
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.
If you include the list[DatetimeLike]
as I suggested, then you should include tests that do intersection()
with lists of those 3 different types. E.g., idx1.intersection([pd.Timestamp(x) for x in idx2])
and something similar for dt.datetime
and np.datetime64
Also, you are failing in CI because of one (or both) of two reasons:
|
@Dr-Irv Thank you for the feedback! I will try to have a better version of this up by the weekend or early next week. |
Fix DatetimeIndex.intersection() return type
The return type of DatetimeIndex.intersection() was incorrectly
specified.This updates the method signature to indicate the correct return
type of DatetimeIndex.
Test added as well.
Fixes #744
assert_type()
to assert the type of any return value