Skip to content

Commit

Permalink
Backport PR pandas-dev#25058: Reading a HDF5 created in py2 (pandas-d…
Browse files Browse the repository at this point in the history
  • Loading branch information
meeseeksmachine authored and jreback committed Feb 4, 2019
1 parent 1700680 commit d8fe711
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Bug Fixes

**I/O**

-
- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 (: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.
17 changes: 16 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,21 @@ 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

0 comments on commit d8fe711

Please sign in to comment.