Skip to content

Commit 11e60d7

Browse files
sofiane87jreback
authored andcommitted
TST: Adding to_dict numeric consistency test (#22620) (#29338)
1 parent 5b332e4 commit 11e60d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/frame/test_convert_to.py

+16
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,19 @@ def test_to_dict_wide(self):
612612
result = df.to_dict("records")[0]
613613
expected = {"A_{:d}".format(i): i for i in range(256)}
614614
assert result == expected
615+
616+
def test_to_dict_orient_dtype(self):
617+
# https://github.com/pandas-dev/pandas/issues/22620
618+
# Input Data
619+
input_data = {"a": [1, 2, 3], "b": [1.0, 2.0, 3.0], "c": ["X", "Y", "Z"]}
620+
df = DataFrame(input_data)
621+
# Expected Dtypes
622+
expected = {"a": int, "b": float, "c": str}
623+
# Extracting dtypes out of to_dict operation
624+
for df_dict in df.to_dict("records"):
625+
result = {
626+
"a": type(df_dict["a"]),
627+
"b": type(df_dict["b"]),
628+
"c": type(df_dict["c"]),
629+
}
630+
assert result == expected

0 commit comments

Comments
 (0)