Skip to content

Commit 590bd44

Browse files
committed
add test for dataframe-to_hdf-datetme64
1 parent 1c986d6 commit 590bd44

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/io/pytables/test_retain_attributes.py

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
date_range,
99
errors,
1010
read_hdf,
11+
to_datetime,
1112
)
1213
from pandas.tests.io.pytables.common import (
1314
_maybe_remove,
@@ -90,3 +91,19 @@ def test_retain_index_attributes2(tmp_path, setup_path):
9091
df2.to_hdf(path, key="data", append=True)
9192

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

0 commit comments

Comments
 (0)