8000 ENH: Improve performance for df.__setitem__ with list-like indexers by phofl · Pull Request #38148 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Improve performance for df.__setitem__ with list-like indexers #38148

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 4 commits into from
Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adress review comments
  • Loading branch information
phofl committed Nov 29, 2020
commit 07b1c52892ba5db9d0d727fd99b8b932ae5a4b56
4 changes: 4 additions & 0 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ def time_assign_list_like_with_setitem(self):
np.random.seed(1234)
self.df[list(range(100))] = np.random.randn(self.N, 100)

def time_assign_list_of_columns_concat(self):
df = DataFrame(np.random.randn(self.N, 100))
concat([self.df, df], axis=1)


class ChainIndexing:

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrame.groupby` aggregation with out-of-bounds datetime objects in an object-dtype column (:issue:`36003`)
- Fixed regression in ``df.groupby(..).rolling(..)`` with the resulting :class:`MultiIndex` when grouping by a label that is in the index (:issue:`37641`)
- Fixed regression in :meth:`DataFrame.fillna` not filling ``NaN`` after other operations such as :meth:`DataFrame.pivot` (:issue:`36495`).
- Fixed performance regression for :meth:`DataFrame.__setitem__` with list-like indexers (:issue:`37954`)

.. ---------------------------------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ Other enhancements
- Improve numerical stability for :meth:`.Rolling.skew`, :meth:`.Rolling.kurt`, :meth:`Expanding.skew` and :meth:`Expanding.kurt` through implementation of Kahan summation (:issue:`6929`)
- Improved error reporting for subsetting columns of a :class:`.DataFrameGroupBy` with ``axis=1`` (:issue:`37725`)
- Implement method ``cross`` for :meth:`DataFrame.merge` and :meth:`DataFrame.join` (:issue:`5401`)
- Improve performance for :meth:`DataFrame.__setitem__` with list-like indexers (:issue:`37954`)

.. ---------------------------------------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None):
and not com.is_bool_indexer(key)
and all(is_hashable(k) for k in key)
):
keys = self.obj.columns.tolist()
keys.extend([k for k in key if k not in self.obj])
keys = self.obj.columns.union(key, sort=False)
self.obj._mgr = self.obj._mgr.reindex_axis(keys, 0)

def __setitem__(self, key, value):
Expand Down
0