Skip to content

PERF: Improve performance in DataFrame.filter #52941

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

Merged
merged 2 commits into from
Apr 27, 2023
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 26, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

this gives a 40% speedup if items is relatively large

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves DataFrame DataFrame data structure labels Apr 26, 2023
@phofl phofl requested a review from Dr-Irv April 26, 2023 19:06
@phofl phofl added the Performance Memory or execution speed performance label Apr 26, 2023
@@ -5586,7 +5586,7 @@ def filter(
name = self._get_axis_name(axis)
# error: Keywords must be strings
return self.reindex( # type: ignore[misc]
**{name: [r for r in items if r in labels]} # type: ignore[arg-type]
**{name: labels.intersection(items)} # type: ignore[arg-type]
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this type: ignore is not needed

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @phofl

@Dr-Irv Dr-Irv merged commit 04527e1 into pandas-dev:main Apr 27, 2023
@phofl phofl deleted the perf_filter branch April 27, 2023 18:19
@mroeschke mroeschke added this to the 2.1 milestone Apr 27, 2023
topper-123 pushed a commit to topper-123/pandas that referenced this pull request May 7, 2023
* PERF: Improve performance in DataFrame.filter

* Update generic.py
Rylie-W pushed a commit to Rylie-W/pandas that referenced this pull request May 19, 2023
* PERF: Improve performance in DataFrame.filter

* Update generic.py
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
* PERF: Improve performance in DataFrame.filter

* Update generic.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFrame DataFrame data structure Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants