From 6efc2432c062962c0b7c7b9026dd34f42a2ada5f Mon Sep 17 00:00:00 2001 From: Aaron Straus Date: Wed, 28 Jun 2017 08:32:30 -0700 Subject: [PATCH] BUG: Fix read of py3 PeriodIndex DataFrame HDF made in py2 (#16781) In Python3, reading a DataFrame with a PeriodIndex from an HDF file created in Python2 would incorrectly return a DataFrame with an Int64Index. --- doc/source/whatsnew/v0.20.3.txt | 1 + pandas/io/pytables.py | 4 ++-- ...periodindex_0.20.1_x86_64_darwin_2.7.13.h5 | Bin 0 -> 7312 bytes pandas/tests/io/test_pytables.py | 20 ++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 pandas/tests/io/data/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index 0fac6367fd3a5..ebbdecb7dc0d0 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -38,6 +38,7 @@ Bug Fixes ~~~~~~~~~ - Fixed issue with dataframe scatter plot for categorical data that reports incorrect column key not found when categorical data is used for plotting (:issue:`16199`) - Fixed a pytest marker failing downstream packages' tests suites (:issue:`16680`) +- Fixed compat with loading a ``DataFrame`` with a ``PeriodIndex``, from a ``format='fixed'`` HDFStore, in Python 3, that was written in Python 2 (:issue:`16781`) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 02b6a772e86b9..4e343556c083b 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2591,8 +2591,8 @@ def read_index_node(self, node, start=None, stop=None): if 'name' in node._v_attrs: name = _ensure_str(node._v_attrs.name) - index_class = self._alias_to_class(getattr(node._v_attrs, - 'index_class', '')) + index_class = self._alias_to_class(_ensure_decoded( + getattr(node._v_attrs, 'index_class', ''))) factory = self._get_index_factory(index_class) kwargs = {} diff --git a/pandas/tests/io/data/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 b/pandas/tests/io/data/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 new file mode 100644 index 0000000000000000000000000000000000000000..6fb92d3c564bdfc290313ab4ef0ca63e1574711e GIT binary patch literal 7312 zcmeGgL2}zhY-u|Qvr$r|Z91Jy558HKY9!Zb(^IU}a;+KH@<>X?KG8I__OO;nmP@5^ zUy$DVj2`=h9CPVR9*}l=%rQSmfnC5o?_HDe!S! zu^_6Z%gtMQe)-H|c+B&A)Nu$tBlzo_?KtA9z`0KeU#0aI=Plwj;Rn5TTL2}m&yc3Y zi>tQhGGYcVl?FE2t!;ea9eQiF(idcBtc-*@Y>yi}@ju~hve%+rS47RMi1zKm-=H(t z1OpZy!4GA#d_x3Hk^Y;_R=*E;q`v|`rvJ9reS|NX)8p!{c--#wJKZfqkFLY?&3Xey zNPpiz2Rseww|57vhnwxbx8Ci2*BW?b{LA$w@m0;5ML(^Q!#yW~|K_KE*+_EY?`H8? zb7?eC^iyk#lca-d*Y8KO6TJ+Q)3*S*!v<5&UpG;-8BcO z$XtcHV2RjI8Z_Q6?Bk53E;WkJ=jt7+28>1c@*sNW1PXbYHfAZ5HcShXF1<3BhUB?xJMeQ>=-yu-Zl6!U#bo#BR_@lO^c%m zJP+`39E)IjhWx#29~(09+5$L}T(i#H+?*kGVIAzuJGF`>VNbK859w`?=G7;Uc8m5> zcHXsmz1A-9%PKcM+4O?kbrI|gl|1!cF zP5gGZjKbpiJblic^T{v#?5of17XKjlCqavS^MGDp)k2pbVP{~bftdzo8klKdrh%CT z-YE^t!#xP*cE!9k&)cqIEZTYh%S|m(%rRqS7!1 zi>-(^X5KNCmMacY^#dZ1{&)DX-3LLO9D7jRNoayN(pfqQvN)AVQ`Q1o_0}^Dt14ZO z4-T}-w0t)P9k52!|56)QKy%3C5V_q&am-