Skip to content

Commit 8e99991

Browse files
code sample for pandas-dev#29824
1 parent aab896d commit 8e99991

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bisect/29824.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# using to_dict with the 'records' orient produces different results from the default one #29824
2+
3+
import datetime
4+
5+
import pandas as pd
6+
7+
print(pd.__version__)
8+
9+
df = pd.DataFrame({"d": pd.date_range("2018-01-01", freq="12h", periods=2)})
10+
for col in df.select_dtypes(["datetime"]):
11+
df[col] = pd.Series(df[col].dt.to_pydatetime(), dtype="object")
12+
13+
result = df.to_dict("records")
14+
print(result)
15+
16+
assert type(result[0]["d"]) is datetime.datetime, type(result[0]["d"])
17+
18+
result = df.to_dict("split")
19+
print(result)
20+
21+
assert type(result["data"][0][0]) is datetime.datetime, type(result["data"][0][0])

0 commit comments

Comments
 (0)