Skip to content

Commit 38f59a1

Browse files
code sample for pandas-dev#46634
1 parent 18a7e94 commit 38f59a1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

bisect/46634.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# BUG: Replace changes the dtype of other columns #46634
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
7+
cat_series = pd.Series(["b", "b", "b", "d"], dtype="category")
8+
df = pd.DataFrame(
9+
{
10+
"id": pd.Series([5, 4, 3, 2], dtype="float64"),
11+
"col": cat_series,
12+
}
13+
)
14+
result = df.replace({3: None})
15+
16+
print(result)
17+
18+
print(result.dtypes)
19+
20+
expected = pd.DataFrame(
21+
{
22+
"id": pd.Series([5.0, 4.0, None, 2.0], dtype="object"),
23+
"col": cat_series,
24+
}
25+
)
26+
27+
pd.testing.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)