Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Datetimelike
^^^^^^^^^^^^
- Bug in :meth:`Series.__setitem__` incorrectly casting ``np.timedelta64("NaT")`` to ``np.datetime64("NaT")`` when inserting into a :class:`Series` with datetime64 dtype (:issue:`27311`)
- Bug in :meth:`Series.dt` property lookups when the underlying data is read-only (:issue:`27529`)
- Bug in ``HDFStore.__getitem__`` incorrectly reading tz attribute created in Python 2 (:issue:`26443`)
-


Expand Down
7 changes: 6 additions & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,12 @@ def read_index_node(self, node, start=None, stop=None):
kwargs["freq"] = node._v_attrs["freq"]

if "tz" in node._v_attrs:
kwargs["tz"] = node._v_attrs["tz"]
if isinstance(node._v_attrs["tz"], bytes):
# created by python2
kwargs["tz"] = node._v_attrs["tz"].decode("utf-8")
else:
# created by python3
kwargs["tz"] = node._v_attrs["tz"]

if kind in ("date", "datetime"):
index = factory(
Expand Down
Binary file added pandas/tests/io/data/legacy_hdf/gh26443.h5
Binary file not shown.
13 changes: 13 additions & 0 deletions pandas/tests/io/pytables/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5446,3 +5446,16 @@ def test_read_with_where_tz_aware_index(self):
store.append(key, expected, format="table", append=True)
result = pd.read_hdf(path, key, where="DATE > 20151130")
assert_frame_equal(result, expected)

def test_py2_created_with_datetimez(self, datapath):
# The test HDF5 file was created in Python 2, but could not be read in
# Python 3.
#
# GH26443
index = [pd.Timestamp("2019-01-01T18:00").tz_localize("America/New_York")]
expected = DataFrame({"data": 123}, index=index)
with ensure_clean_store(
datapath("io", "data", "legacy_hdf", "gh26443.h5"), mode="r"
) as store:
result = store["key"]
assert_frame_equal(result, expected)