Skip to content

Commit dd1ec02

Browse files
Fix value error when reading dataframe saved in python 2 in python 3
1 parent da5f5eb commit dd1ec02

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pandas/io/pytables.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 1 deletion
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,20 @@ 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+
# GH xxxxx
4557+
# legacy table written en 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+
expected = pd.DataFrame({
4564+
"a": ["a", "b"],
4565+
"b": [2, 3]
4566+
})
4567+
assert_frame_equal(expected, result)
4568+
45554569
def test_legacy_table_read(self, datapath):
45564570
# legacy table types
45574571
with ensure_clean_store(

0 commit comments

Comments
 (0)