From b985cc312a55d465bfbdb5abf3f7d2ca57bf2185 Mon Sep 17 00:00:00 2001 From: Ayla Khan Date: Sun, 12 Apr 2020 18:30:22 -0600 Subject: [PATCH 1/4] ENH: clearer error message if read_hdf loads upsupported HDF file (GH9539) --- doc/source/whatsnew/v1.1.0.rst | 2 ++ pandas/io/pytables.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 5fe7d12188860..c126498f67539 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -98,6 +98,8 @@ Other enhancements This can be used to set a custom compression level, e.g., ``df.to_csv(path, compression={'method': 'gzip', 'compresslevel': 1}`` (:issue:`33196`) +- :func:`pandas.read_hdf` has a more explicit error message when loading an + unsupported HDF file (:issue:`9539`) .. --------------------------------------------------------------------------- diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 3dd87ae6ed758..be943349c18d3 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -387,7 +387,10 @@ def read_hdf( if key is None: groups = store.groups() if len(groups) == 0: - raise ValueError("No dataset in HDF5 file.") + raise ValueError( + "Dataset that is either compatible with Pandas data types " + "or is a table could not be found in HDF5 file." + ) candidate_only_group = groups[0] # For the HDF file to have only one dataset, all other groups From a60e997ebe2ff68ed4c239a2d1daaa7e559c8fdf Mon Sep 17 00:00:00 2001 From: Ayla Khan Date: Mon, 13 Apr 2020 02:45:40 +0000 Subject: [PATCH 2/4] ENH: less convoluted error message (GH9539) --- pandas/io/pytables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index be943349c18d3..425118694fa02 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -388,8 +388,8 @@ def read_hdf( groups = store.groups() if len(groups) == 0: raise ValueError( - "Dataset that is either compatible with Pandas data types " - "or is a table could not be found in HDF5 file." + "Dataset(s) incompatible with Pandas data types, " + "not table, or no datasets found in HDF5 file." ) candidate_only_group = groups[0] From 578c56e32edf68c8533d64276ce8f0caedf793af Mon Sep 17 00:00:00 2001 From: Ayla Khan Date: Sun, 12 Apr 2020 22:29:15 -0600 Subject: [PATCH 3/4] ENH: adding file with an incompatible dataset based on PR feedback and a test (GH9539) --- .../io/data/legacy_hdf/incompatible_dataset.h5 | Bin 0 -> 4480 bytes pandas/tests/io/pytables/test_store.py | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 pandas/tests/io/data/legacy_hdf/incompatible_dataset.h5 diff --git a/pandas/tests/io/data/legacy_hdf/incompatible_dataset.h5 b/pandas/tests/io/data/legacy_hdf/incompatible_dataset.h5 new file mode 100644 index 0000000000000000000000000000000000000000..50fbee0f5018b48c8df5a1f4c82c2fd7092a959b GIT binary patch literal 4480 zcmeHJ3rv$&6#mR(Z8NTH2IXEg%S;wf~F~j!8Z5*+;opfXBwVK8GLLLfNSOY?u(`OM zipQUf`;^6CV9$|6d_v;Ouy!MZW@`}8(~mvjQ~it?ZM>qRjHio$vMZ~S$`x78GXU$FuI6ZmBQ+TnSn;QS%d{5yX` zzX*#D!yN>V-3Z`I$^c(KPd$eT-r3>2CE`uy@k@q%>tG~oy5TIr3rE5Xogh&R2BM8G zD=E)!MEy#t9m0D<$6RM%t~$IwM$fH!KbcH^@c|S32BnbP@K!2tq@fkF@hEz*^W*d# zf1Q*D|LdOn6MKq(^6o;a8^3d?F&${n?uF);hEx#z;OsP?eS@${7wpF4cfe;?gb8^T zqj1Q`J*$S+5A$So=Tij_(X0#W(_%9kq12^2bI%{0;P7qng9+szRIFhR4|mC6#hM|O zvxOX8=jFQlr%Mq}a5Sg3zZq`dB~j-zKSb<$`$lh`7`ck;KV&c`ka1jcXtYBa{6=!% zI&o@|n!{w-*|ws^WZAmfh*ofNesZoY91{$>c#5OUdO&3TU7Y=x5*S&ed*PLLVClMA z^ZCmA5aBk!-`Z9Qn`;}y%paej)zUt8e)uRFSBZOF@*APmwN|@VT?N;6ShurJHGsRC z5*|Uh3A7s=@{wB&+%Dv3dJt_{pafyc zM8$cI3K~{Qr3zLHG>}#_nSA~T#ZlI?(}qQeSC%*~VGn@6d8X26OaPYK*{)rIj}VwT zu=$4-Xoz;gs%PXW5?rtq$s#*p(Vi+6OHzln(t-ny#mQl*m8J0nBM*gYb7s@COVQAh z_>XAYL~!M5Jbzx027V|%oDzPz8%}yl&R*VFhh{9!mNXUL17C%*blJ3VR5$!pfbmHl zoDO#1;HYhaRpavXm6;uID8QHHwMC5tt!B&bTPab-K}6NEgowQU;DVT-ekeXOvu&dM z5xj5J;do-X7VXXNu1wg%E`(X<%&M0vpq{+k zqM+;+gbZ~$pE55(2W)rI%xn74;MXn|nuH3}TlCb%^5A8E!viS|LxtvtPr;zD))8Oc4%0r-?jQ1FPuNA2-g%sYlFM)|?wzLQ0 zG32fiT>i$H4+Zv%>K3*LQDUJ=o>5%_yPL9XexZ*-MO Date: Thu, 16 Apr 2020 20:26:27 -0600 Subject: [PATCH 4/4] Move note to io section as requested in PR feedback. --- doc/source/whatsnew/v1.1.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 24b1be3e42df7..e0f01ebe52705 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -98,8 +98,6 @@ Other enhancements This can be used to set a custom compression level, e.g., ``df.to_csv(path, compression={'method': 'gzip', 'compresslevel': 1}`` (:issue:`33196`) -- :func:`pandas.read_hdf` has a more explicit error message when loading an - unsupported HDF file (:issue:`9539`) .. --------------------------------------------------------------------------- @@ -531,6 +529,8 @@ I/O - Bug in :meth:`DataFrame.to_sql` where an ``AttributeError`` was raised when saving an out of bounds date (:issue:`26761`) - Bug in :meth:`read_excel` did not correctly handle multiple embedded spaces in OpenDocument text cells. (:issue:`32207`) - Bug in :meth:`read_json` was raising ``TypeError`` when reading a list of booleans into a Series. (:issue:`31464`) +- :func:`pandas.read_hdf` has a more explicit error message when loading an + unsupported HDF file (:issue:`9539`) Plotting ^^^^^^^^