Skip to content

Commit

Permalink
code sample for pandas-dev#42477
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins committed Jul 16, 2021
1 parent 0071de3 commit a7e15c0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bisect/42477.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a7e15c0

Please sign in to comment.