From a7e15c0af2e8fe5ac9c00bddb0a9111d5acdefde Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 16 Jul 2021 12:45:28 +0100 Subject: [PATCH] code sample for #42477 --- bisect/42477.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bisect/42477.py diff --git a/bisect/42477.py b/bisect/42477.py new file mode 100644 index 0000000000000..fad31059dd294 --- /dev/null +++ b/bisect/42477.py @@ -0,0 +1,21 @@ +# 1.3.0 PerformanceWarning: DataFrame is highly fragmented. #42477 + +import numpy as np +import pandas as pd + +print(pd.__version__) + +df = pd.DataFrame( + {"a": np.random.randint(0, 100, size=55), "b": np.random.randint(0, 100, size=55)} +) + +# Assign > 100 new columns to the dataframe +for i in range(0, 100): + df.loc[:, f"n_{i}"] = np.random.randint(0, 100, size=55) + # Alternative assignment - triggers Performancewarnings here already. + # df[f'n_{i}'] = np.random.randint(0, 100, size=55) +print(df._data.nblocks) + +df1 = df.copy() +result = df1._data.nblocks +assert result == 1, result