From dd1ec0271d1dd7193d1ebbfa40ac5948646002dc Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Thu, 31 Jan 2019 18:31:42 +0100 Subject: [PATCH 1/7] Fix value error when reading dataframe saved in python 2 in python 3 --- pandas/io/pytables.py | 2 +- .../io/data/legacy_hdf/legacy_table_py2.h5 | Bin 0 -> 72279 bytes pandas/tests/io/test_pytables.py | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 pandas/tests/io/data/legacy_hdf/legacy_table_py2.h5 diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 4e103482f48a2..2ab6ddb5b25c7 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -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 = [ diff --git a/pandas/tests/io/data/legacy_hdf/legacy_table_py2.h5 b/pandas/tests/io/data/legacy_hdf/legacy_table_py2.h5 new file mode 100644 index 0000000000000000000000000000000000000000..3863d714a315b79de100e8446db766ec7dc2e82c GIT binary patch literal 72279 zcmeI#%}yIv6u|K@5O5q*2$iaeZdlb`Axyqlh89yS8G|rwQmN8(j3>yd8C$l4(p{JB zTXdNR=^~HPw`k9~cMcu~oF-KlRq`M3jOWh%IP;r(?_B?Ou(!WlS}z5<6^p?_uA=CK^3k@feV0jg`TSouciU}A*Zg1Ir>&_bedmlF9zS$Puh*6 zmdme0$MV-Ux8zLo@3><@Mw;e7{{D3Lt7g3&?jM~T?w*FT%5QJh(sFCA&ipuCO$XfS zg3A{C(>UE(_W9Cc{)GKUBQR^64%7MDApYxd+HM`~6{H7SzbmHw)yBzIdVZXX!{XuS z1#G^{drjw~|J!_5cJtjZO1jZFocui0+27Br_vC2L|HUY}h(qgjI$!#Evk zDm)wX$1d5G|H57O=hgnOR;o6(O6`ivS}6^;OOxS)QncwZl!K@4Sdcr?dH*u%zl_Jz z3ibW6CLfE()z_{>l~UBMbY$U26AKWyq zWfxaBnnW7a%ZtR_>AS~Ol~y%={~k=DBpk)V8}C6$cloBz^{y)sCuf6hFFAJ?WvA`x zlEFM$SNCu2EctSy(O@KzYW{3L7*9sMvq`r9EIIjpd>QLA)c2+Q%l6dmtsOh&#62X04muYFEll^ZWT? z_PY0pHY52r+|jS&7jCTMWv>je2u0+zMN}hq~-{<1o99xBh>7x!SdI zdguP`gCNq%WV^lG_RMlN7N)-gmZgqjU~%p@noX@YI~MfZ+STv6-QI33wDLCgZkDs( zAK7-dugbl9yV>{RPr~Tq(sq~RW9{~mNqioUGV%I(I|_Xn&96h!@@L+AZpNSX6Dy}P zv44*Gz^&ZP_k-_OQP_2BjeK1Cen`%DZp77jdt6s<;(T14@crWIWa7HsA199=Iuq;1 zixOioXq_BAYfJj9=i@rRT-V=yy1uq?IX%k7Tej!x*AsP8)lJ_GYzQEL00Iag@L>x? zwt%n&RVV$y_+j5RcZUE12q1s}0tg_000IagfB*srAb Date: Thu, 31 Jan 2019 18:46:59 +0100 Subject: [PATCH 2/7] Typo fixed --- pandas/tests/io/test_pytables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index bd88206072f47..49744d192c9b5 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4554,7 +4554,7 @@ def test_legacy_table_fixed_format_read_py2(self, datapath): def test_legacy_table_read_py2(self, datapath): # GH xxxxx - # legacy table written en Python 2 + # legacy table written in Python 2 with ensure_clean_store( datapath('io', 'data', 'legacy_hdf', 'legacy_table_py2.h5'), From 70c7ab197fa216079fd4a9b913fddca9f70bcc66 Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Thu, 31 Jan 2019 18:53:22 +0100 Subject: [PATCH 3/7] Bug description --- doc/source/whatsnew/v0.24.1.rst | 2 +- pandas/tests/io/test_pytables.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.1.rst b/doc/source/whatsnew/v0.24.1.rst index 521319c55a503..d0be8c518bc59 100644 --- a/doc/source/whatsnew/v0.24.1.rst +++ b/doc/source/whatsnew/v0.24.1.rst @@ -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`) - - diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 49744d192c9b5..28b7e4aefc129 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4553,7 +4553,7 @@ def test_legacy_table_fixed_format_read_py2(self, datapath): assert_frame_equal(expected, result) def test_legacy_table_read_py2(self, datapath): - # GH xxxxx + # issue: 24925 # legacy table written in Python 2 with ensure_clean_store( datapath('io', 'data', 'legacy_hdf', From 0fa7102f96fde9b2f70a2cddb070ff973963d940 Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Fri, 1 Feb 2019 11:38:29 +0100 Subject: [PATCH 4/7] Construct expected dataframe and assert outside of with statement --- pandas/tests/io/test_pytables.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 28b7e4aefc129..ba9f6a137cbeb 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4560,11 +4560,12 @@ def test_legacy_table_read_py2(self, datapath): '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) + + expected = pd.DataFrame({ + "a": ["a", "b"], + "b": [2, 3] + }) + assert_frame_equal(expected, result) def test_legacy_table_read(self, datapath): # legacy table types From f9ab13353ce86b3a7c00cbf836879422605236d0 Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Fri, 1 Feb 2019 11:43:13 +0100 Subject: [PATCH 5/7] Pep8 warning fixed --- pandas/tests/io/test_pytables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index ba9f6a137cbeb..9430011288f27 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4560,7 +4560,7 @@ def test_legacy_table_read_py2(self, datapath): 'legacy_table_py2.h5'), mode='r') as store: result = store.select('table') - + expected = pd.DataFrame({ "a": ["a", "b"], "b": [2, 3] From abf6c3541f061f6aed5290120972bffa361e4c5e Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Fri, 1 Feb 2019 20:12:50 +0100 Subject: [PATCH 6/7] Documentation updated, moved to 0.24.2 --- doc/source/whatsnew/v0.24.1.rst | 2 +- doc/source/whatsnew/v0.24.2.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.1.rst b/doc/source/whatsnew/v0.24.1.rst index 16ac7c94777f5..c8b5417a5b77f 100644 --- a/doc/source/whatsnew/v0.24.1.rst +++ b/doc/source/whatsnew/v0.24.1.rst @@ -52,7 +52,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`) +- - - diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index cba21ce7ee1e6..f71241b630fb8 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -51,7 +51,7 @@ Bug Fixes **I/O** -- +- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 - - From 12043014ba2edb80089a88d345cb49805cc9ab0a Mon Sep 17 00:00:00 2001 From: Radek Benes Date: Fri, 1 Feb 2019 20:34:38 +0100 Subject: [PATCH 7/7] Issue number is back in documentation --- doc/source/whatsnew/v0.24.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index f71241b630fb8..316fc21c126ac 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -51,7 +51,7 @@ Bug Fixes **I/O** -- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 +- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 (:issue:`24925`) - -