-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Avoid duplicates in DatetimeIndex.intersection #38196
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
@@ -687,7 +687,7 @@ def intersection(self, other, sort=False): | |||
self._validate_sort_keyword(sort) | |||
self._assert_can_do_setop(other) | |||
|
|||
if self.equals(other): | |||
if self.equals(other) and not self.has_duplicates: | |||
return self._get_reconciled_name_object(other) |
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.
should we handle the self.equals(other) but non-unique case here? (like MultIIndex i think)
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.
Should be consistent. best would probably be to handle this here.
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.
Handled it here now, and called _convert_can_do_setop. Have seen you moved the remaining part to _intersection in #38190, so I will keep this here as it is now that we are consistent
pd.Timestamp("2019-12-12"), | ||
] | ||
) | ||
result = idx1.intersection(idx1) |
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.
sort?
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.
Hm good point. Parametrized the test
yah im pretty sure that test is wrong xref #38111 |
Fixed the test |
thanks @phofl very nice |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
@jbrockmendel I think we should call
_convert_can_do_setop
here too, butpandas/pandas/tests/indexes/datetimes/test_setops.py
Line 472 in 56b9a80