Skip to content

Commit a96bdbd

Browse files
authored
BUG Decode to UTF-8 the dtype string read from a hdf file (#31756)
1 parent c4e8eb3 commit a96bdbd

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ I/O
185185
- Bug in :meth:`DataFrame.to_parquet` overwriting pyarrow's default for
186186
``coerce_timestamps``; following pyarrow's default allows writing nanosecond
187187
timestamps with ``version="2.0"`` (:issue:`31652`).
188+
- Bug in :class:`HDFStore` that caused it to set to ``int64`` the dtype of a ``datetime64`` column when reading a DataFrame in Python 3 from fixed format written in Python 2 (:issue:`31750`)
188189

189190
Plotting
190191
^^^^^^^^

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,7 @@ def read_array(
27222722
if isinstance(node, tables.VLArray):
27232723
ret = node[0][start:stop]
27242724
else:
2725-
dtype = getattr(attrs, "value_type", None)
2725+
dtype = _ensure_decoded(getattr(attrs, "value_type", None))
27262726
shape = getattr(attrs, "shape", None)
27272727

27282728
if shape is not None:
Binary file not shown.

pandas/tests/io/pytables/test_store.py

+15
Original file line numberDiff line numberDiff line change
@@ -4074,6 +4074,21 @@ def test_legacy_table_fixed_format_read_py2(self, datapath, setup_path):
40744074
)
40754075
tm.assert_frame_equal(expected, result)
40764076

4077+
def test_legacy_table_fixed_format_read_datetime_py2(self, datapath, setup_path):
4078+
# GH 31750
4079+
# legacy table with fixed format and datetime64 column written in Python 2
4080+
with ensure_clean_store(
4081+
datapath("io", "data", "legacy_hdf", "legacy_table_fixed_datetime_py2.h5"),
4082+
mode="r",
4083+
) as store:
4084+
result = store.select("df")
4085+
expected = pd.DataFrame(
4086+
[[pd.Timestamp("2020-02-06T18:00")]],
4087+
columns=["A"],
4088+
index=pd.Index(["date"]),
4089+
)
4090+
tm.assert_frame_equal(expected, result)
4091+
40774092
def test_legacy_table_read_py2(self, datapath, setup_path):
40784093
# issue: 24925
40794094
# legacy table written in Python 2

0 commit comments

Comments
 (0)