Skip to content

Commit 04527e1

Browse files
authored
PERF: Improve performance in DataFrame.filter (#52941)
* PERF: Improve performance in DataFrame.filter * Update generic.py
1 parent 196775a commit 04527e1

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Other enhancements
9696
- Let :meth:`DataFrame.to_feather` accept a non-default :class:`Index` and non-string column names (:issue:`51787`)
9797
- Performance improvement in :func:`read_csv` (:issue:`52632`) with ``engine="c"``
9898
- Performance improvement in :func:`concat` with homogeneous ``np.float64`` or ``np.float32`` dtypes (:issue:`52685`)
99+
- Performance improvement in :meth:`DataFrame.filter` when ``items`` is given (:issue:`52941`)
99100
-
100101

101102
.. ---------------------------------------------------------------------------

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5586,7 +5586,7 @@ def filter(
55865586
name = self._get_axis_name(axis)
55875587
# error: Keywords must be strings
55885588
return self.reindex( # type: ignore[misc]
5589-
**{name: [r for r in items if r in labels]} # type: ignore[arg-type]
5589+
**{name: labels.intersection(items)}
55905590
)
55915591
elif like:
55925592

0 commit comments

Comments
 (0)