Skip to content

Commit ec017f9

Browse files
code sample for pandas-dev#42099
1 parent 35ce475 commit ec017f9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bisect/42099.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# BUG: Adding Series to empty DataFrame can reset dtype to float64 #42099
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
7+
data = pd.array([0, 1, 2, 3], dtype="Int32")
8+
df = pd.DataFrame({"data": pd.Series(data)})
9+
10+
result = pd.DataFrame(index=df.index)
11+
12+
result.loc[df.index, "data"] = df["data"]
13+
14+
expected_dtype = df["data"].dtype
15+
dtype = result["data"].dtype
16+
17+
print(dtype) # prints: float64 <--
18+
19+
assert dtype == expected_dtype

0 commit comments

Comments
 (0)