Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Performance improvements
- Performance improvement in :func:`merge` and :meth:`DataFrame.join` for many-to-many joins with ``sort=False`` (:issue:`56564`)
- Performance improvement in :func:`merge` with ``how="cross"`` (:issue:`38082`)
- Performance improvement in :func:`merge` with ``how="left"`` (:issue:`64370`)
- Performance improvement in :meth:`DataFrame.insert` when the number of blocks is small (:issue:`57641`)
- Performance improvement in :meth:`DataFrame.loc` with non-unique masked index (:issue:`56759`)
- Performance improvement in :meth:`DataFrame.to_stata` when writing object-dtype datetime columns with date formats that require year/month extraction (:issue:`64555`)
- Performance improvement in :meth:`GroupBy.any` and :meth:`GroupBy.all` for boolean-dtype columns (:issue:`37850`)
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,11 @@ def insert(self, loc: int, item: Hashable, value: ArrayLike, refs=None) -> None:
self._known_consolidated = False
self.blocks += (block,)

# len check is a cheap O(1) short-circuit to avoid the O(n) sum
# and the get_option overhead on every insert call (GH#57641)
if (
get_option("performance_warnings")
len(self.blocks) > 100
and get_option("performance_warnings")
and sum(not block.is_extension for block in self.blocks) > 100
):
warnings.warn(
Expand Down
Loading