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

BUG: fix PeriodIndex.difference producing incorrect results #60992

Conversation

chilin0525
Copy link
Contributor

@@ -534,6 +534,22 @@ def shift(self, periods: int = 1, freq=None) -> Self:
)
return self + periods

def _convert_can_do_setop(self, other):
try:
if isinstance(other, Index):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this can be outside a try/except

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel Thank you for the review, but before submitting the revision, I would like to confirm with you whether you think this modification direction is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel Thank you for your previous feedback on my PR . I have addressed your suggestions and made the improvements accordingly. I would love to get your thoughts on the updated changes. Thanks!

@@ -691,6 +691,7 @@ Indexing
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`)
- Bug in :meth:`DataFrame.from_records` throwing a ``ValueError`` when passed an empty list in ``index`` (:issue:`58594`)
- Bug in :meth:`MultiIndex.insert` when a new value inserted to a datetime-like level gets cast to ``NaT`` and fails indexing (:issue:`60388`)
- Bug in :meth:`PeriodIndex.difference` producing incorrect results when operating between :class:`PeriodIndex` and :class:`Index` objects (:issue:`58971`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the affected Index objects object-dtype?

index2 = pd.Index(["2022-02", "2022-03"])

result1 = index1.difference(index2)
expected1 = PeriodIndex(["2022-01", "2022-04", "2022-05"], freq="M")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is wrong and the result in main is correct.


# Convert non-PeriodIndex to PeriodIndex
try:
other = PeriodIndex(other, freq=self.freq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we should be doing this casting implicitly. the user should do it explicitly if they want it.

Copy link
Contributor

github-actions bot commented Apr 4, 2025

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Apr 4, 2025
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Index.difference is returning too many values
3 participants