Skip to content

Commit a7e15c0

Browse files
code sample for pandas-dev#42477
1 parent 0071de3 commit a7e15c0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bisect/42477.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 1.3.0 PerformanceWarning: DataFrame is highly fragmented. #42477
2+
3+
import numpy as np
4+
import pandas as pd
5+
6+
print(pd.__version__)
7+
8+
df = pd.DataFrame(
9+
{"a": np.random.randint(0, 100, size=55), "b": np.random.randint(0, 100, size=55)}
10+
)
11+
12+
# Assign > 100 new columns to the dataframe
13+
for i in range(0, 100):
14+
df.loc[:, f"n_{i}"] = np.random.randint(0, 100, size=55)
15+
# Alternative assignment - triggers Performancewarnings here already.
16+
# df[f'n_{i}'] = np.random.randint(0, 100, size=55)
17+
print(df._data.nblocks)
18+
19+
df1 = df.copy()
20+
result = df1._data.nblocks
21+
assert result == 1, result

0 commit comments

Comments
 (0)