From f1664e402bf14188511b5a81d81cd6f239129c80 Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Sun, 8 Aug 2021 21:19:59 -0400 Subject: [PATCH 1/3] ERR: clarify PerformanceWarning for fragmented frame --- doc/source/whatsnew/v1.3.2.rst | 2 ++ pandas/core/internals/managers.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index f54cea744f4d2..3a901cda592a3 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -45,8 +45,10 @@ Bug fixes Other ~~~~~ - :meth:`pandas.read_parquet` now supports reading nullable dtypes with ``fastparquet`` versions above 0.7.1. +- Clarified suggested fix for ``PerformanceWarning`` emitted with a highly fragmented :class:`DataFrame` (:issue:`42579`) - + .. --------------------------------------------------------------------------- .. _whatsnew_132.contributors: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 7c8b289e6eb87..e49b272c69a4a 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1177,9 +1177,9 @@ def insert(self, loc: int, item: Hashable, value: ArrayLike) -> None: if len(self.blocks) > 100: warnings.warn( "DataFrame is highly fragmented. This is usually the result " - "of calling `frame.insert` many times, which has poor performance. " - "Consider using pd.concat instead. To get a de-fragmented frame, " - "use `newframe = frame.copy()`", + "of calling `frame.insert` many times, which has poor performance. " + "Consider joining all columns at once using pd.concat(axis=1) instead. " + "To get a de-fragmented frame, use `newframe = frame.copy()`", PerformanceWarning, stacklevel=5, ) From f161c4d1c0e3ea3b221b823c21af026ca41dd282 Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Sun, 8 Aug 2021 21:23:03 -0400 Subject: [PATCH 2/3] Fix spacing --- doc/source/whatsnew/v1.3.2.rst | 1 - pandas/core/internals/managers.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index 3a901cda592a3..68ecbfbfca88d 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -48,7 +48,6 @@ Other - Clarified suggested fix for ``PerformanceWarning`` emitted with a highly fragmented :class:`DataFrame` (:issue:`42579`) - - .. --------------------------------------------------------------------------- .. _whatsnew_132.contributors: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index e49b272c69a4a..72bc489c07aeb 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1177,9 +1177,9 @@ def insert(self, loc: int, item: Hashable, value: ArrayLike) -> None: if len(self.blocks) > 100: warnings.warn( "DataFrame is highly fragmented. This is usually the result " - "of calling `frame.insert` many times, which has poor performance. " - "Consider joining all columns at once using pd.concat(axis=1) instead. " - "To get a de-fragmented frame, use `newframe = frame.copy()`", + "of calling `frame.insert` many times, which has poor performance. " + "Consider joining all columns at once using pd.concat(axis=1) " + "instead. To get a de-fragmented frame, use `newframe = frame.copy()`", PerformanceWarning, stacklevel=5, ) From d5b67ce69d8166a8f0bbcc6bc16e201107ac218e Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Mon, 9 Aug 2021 09:09:48 -0400 Subject: [PATCH 3/3] Remove whatsnew note --- doc/source/whatsnew/v1.3.2.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index 68ecbfbfca88d..f54cea744f4d2 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -45,7 +45,6 @@ Bug fixes Other ~~~~~ - :meth:`pandas.read_parquet` now supports reading nullable dtypes with ``fastparquet`` versions above 0.7.1. -- Clarified suggested fix for ``PerformanceWarning`` emitted with a highly fragmented :class:`DataFrame` (:issue:`42579`) - .. ---------------------------------------------------------------------------