Skip to content

Reading a HDF5 created in py2 #25058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 4, 2019
Merged
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Bug Fixes

**I/O**

-
- Bug in :class:`HDFStore` that caused it to raise ``ValueError`` when reading a Dataframe in Python 3 from dataframe written in Python 2 (:issue:`24925`)
-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3288,7 +3288,7 @@ def get_attrs(self):
self.nan_rep = getattr(self.attrs, 'nan_rep', None)
self.encoding = _ensure_encoding(
getattr(self.attrs, 'encoding', None))
self.errors = getattr(self.attrs, 'errors', 'strict')
self.errors = _ensure_decoded(getattr(self.attrs, 'errors', 'strict'))
self.levels = getattr(
self.attrs, 'levels', None) or []
self.index_axes = [
Expand Down
Binary file not shown.
16 changes: 15 additions & 1 deletion pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4540,7 +4540,7 @@ def test_pytables_native2_read(self, datapath):

def test_legacy_table_fixed_format_read_py2(self, datapath):
# GH 24510
# legacy table with fixed format written en Python 2
# legacy table with fixed format written in Python 2
with ensure_clean_store(
datapath('io', 'data', 'legacy_hdf',
'legacy_table_fixed_py2.h5'),
Expand All @@ -4552,6 +4552,20 @@ def test_legacy_table_fixed_format_read_py2(self, datapath):
name='INDEX_NAME'))
assert_frame_equal(expected, result)

def test_legacy_table_read_py2(self, datapath):
# issue: 24925
# legacy table written in Python 2
with ensure_clean_store(
datapath('io', 'data', 'legacy_hdf',
'legacy_table_py2.h5'),
mode='r') as store:
result = store.select('table')
expected = pd.DataFrame({
"a": ["a", "b"],
"b": [2, 3]
})
assert_frame_equal(expected, result)

def test_legacy_table_read(self, datapath):
# legacy table types
with ensure_clean_store(
Expand Down