Skip to content

Commit bebb60c

Browse files
committed
CLN/TST: add bool test case & DRY the test
1 parent a0d1ffb commit bebb60c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pandas/tests/frame/methods/test_to_dict.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,26 @@ def test_to_dict_orient_dtype(self):
261261

262262
df = DataFrame(
263263
{
264-
"a": [1, 2, 3],
265-
"b": [1.0, 2.0, 3.0],
266-
"c": ["X", "Y", "Z"],
267-
"d": [datetime(2018, 1, 1), datetime(2019, 2, 2), datetime(2020, 3, 3)],
264+
"bool": [True, True, False],
265+
"datetime": [
266+
datetime(2018, 1, 1),
267+
datetime(2019, 2, 2),
268+
datetime(2020, 3, 3),
269+
],
270+
"float": [1.0, 2.0, 3.0],
271+
"int": [1, 2, 3],
272+
"str": ["X", "Y", "Z"],
268273
}
269274
)
270275

271-
expected = {"a": int, "b": float, "c": str, "d": datetime}
276+
expected = {
277+
"int": int,
278+
"float": float,
279+
"str": str,
280+
"datetime": datetime,
281+
"bool": bool,
282+
}
272283

273284
for df_dict in df.to_dict("records"):
274-
result = {
275-
"a": type(df_dict["a"]),
276-
"b": type(df_dict["b"]),
277-
"c": type(df_dict["c"]),
278-
"d": type(df_dict["d"]),
279-
}
285+
result = {col: type(df_dict[col]) for col in list(df.columns)}
280286
assert result == expected

0 commit comments

Comments
 (0)