Skip to content

Commit 33ef3d7

Browse files
code sample for pandas-dev#46297
1 parent 5a74464 commit 33ef3d7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

bisect/46297.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# BUG: Error writing DataFrame with categorical type column and interval data to a CSV file #46297
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
7+
df = pd.DataFrame(index=[0], columns=["a"])
8+
df.at[0, "a"] = pd.Interval(pd.Timestamp("2020-01-01"), pd.Timestamp("2020-01-02"))
9+
df["a"] = df["a"].astype("category") # astype("object") does not raise an error
10+
11+
result = df.to_csv()
12+
print(result)
13+
14+
expected = ',a\n0,"(2020-01-01, 2020-01-02]"\n'
15+
assert result == expected

0 commit comments

Comments
 (0)