Skip to content

Commit 6cacfa9

Browse files
rbenesPingviinituutti
authored andcommitted
Reading a HDF5 created in py2 (pandas-dev#25058)
1 parent 0fa9f13 commit 6cacfa9

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

doc/source/whatsnew/v0.24.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Bug Fixes
5151

5252
**I/O**
5353

54-
-
54+
- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 (:issue:`24925`)
5555
-
5656
-
5757

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3288,7 +3288,7 @@ def get_attrs(self):
32883288
self.nan_rep = getattr(self.attrs, 'nan_rep', None)
32893289
self.encoding = _ensure_encoding(
32903290
getattr(self.attrs, 'encoding', None))
3291-
self.errors = getattr(self.attrs, 'errors', 'strict')
3291+
self.errors = _ensure_decoded(getattr(self.attrs, 'errors', 'strict'))
32923292
self.levels = getattr(
32933293
self.attrs, 'levels', None) or []
32943294
self.index_axes = [
Binary file not shown.

pandas/tests/io/test_pytables.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -4540,7 +4540,7 @@ def test_pytables_native2_read(self, datapath):
45404540

45414541
def test_legacy_table_fixed_format_read_py2(self, datapath):
45424542
# GH 24510
4543-
# legacy table with fixed format written en Python 2
4543+
# legacy table with fixed format written in Python 2
45444544
with ensure_clean_store(
45454545
datapath('io', 'data', 'legacy_hdf',
45464546
'legacy_table_fixed_py2.h5'),
@@ -4552,6 +4552,21 @@ def test_legacy_table_fixed_format_read_py2(self, datapath):
45524552
name='INDEX_NAME'))
45534553
assert_frame_equal(expected, result)
45544554

4555+
def test_legacy_table_read_py2(self, datapath):
4556+
# issue: 24925
4557+
# legacy table written in Python 2
4558+
with ensure_clean_store(
4559+
datapath('io', 'data', 'legacy_hdf',
4560+
'legacy_table_py2.h5'),
4561+
mode='r') as store:
4562+
result = store.select('table')
4563+
4564+
expected = pd.DataFrame({
4565+
"a": ["a", "b"],
4566+
"b": [2, 3]
4567+
})
4568+
assert_frame_equal(expected, result)
4569+
45554570
def test_legacy_table_read(self, datapath):
45564571
# legacy table types
45574572
with ensure_clean_store(

0 commit comments

Comments
 (0)