Skip to content

Commit 9537cf4

Browse files
authored
TST: Add test for retaining dtype of datetime columns in DataFrame.to_hdf (#61112)
* add test for dataframe-to_hdf-datetme64 * improve initialization of series
1 parent 3c93d06 commit 9537cf4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/io/pytables/test_retain_attributes.py

+13
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,16 @@ def test_retain_index_attributes2(tmp_path, setup_path):
9090
df2.to_hdf(path, key="data", append=True)
9191

9292
assert read_hdf(path, "data").index.name is None
93+
94+
95+
def test_retain_datetime_attribute(tmp_path, setup_path):
96+
path = tmp_path / setup_path
97+
ser = Series(
98+
["2024-08-26 15:13:14", "2024-08-26 15:14:14"],
99+
dtype="datetime64[us, UTC]",
100+
)
101+
dataframe = DataFrame(ser)
102+
dataframe.to_hdf(path, key="Annotations", mode="w")
103+
104+
recovered_dataframe = read_hdf(path, key="Annotations")
105+
tm.assert_frame_equal(dataframe, recovered_dataframe)

0 commit comments

Comments
 (0)