diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 7c7112bae0ff3..0f716dad9a2f2 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -666,6 +666,7 @@ I/O - Added ``cache_dates=True`` parameter to :meth:`read_csv`, which allows to cache unique dates when they are parsed (:issue:`25990`) - :meth:`DataFrame.to_excel` now raises a ``ValueError`` when the caller's dimensions exceed the limitations of Excel (:issue:`26051`) - :func:`read_excel` now raises a ``ValueError`` when input is of type :class:`pandas.io.excel.ExcelFile` and ``engine`` param is passed since :class:`pandas.io.excel.ExcelFile` has an engine defined (:issue:`26566`) +- Bug while selecting from :class:`HDFStore` with ``where=''`` specified (:issue:`26610`). Plotting ^^^^^^^^ diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 53ef2395a302a..983b1286eec91 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -98,7 +98,7 @@ def _ensure_term(where, scope_level): where = wlist elif maybe_expression(where): where = Term(where, scope_level=level) - return where + return where if where is None or len(where) else None class PossibleDataLossError(Exception): diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 8b5907b920cca..5c9c3ae46df23 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4731,6 +4731,21 @@ def test_read_py2_hdf_file_in_py3(self, datapath): result = store['p'] assert_frame_equal(result, expected) + @pytest.mark.parametrize("where", ["", (), (None, ), [], [None]]) + def test_select_empty_where(self, where): + # GH26610 + + # Using keyword `where` as '' or (), or [None], etc + # while reading from HDF store raises + # "SyntaxError: only a single expression is allowed" + + df = pd.DataFrame([1, 2, 3]) + with ensure_clean_path("empty_where.h5") as path: + with pd.HDFStore(path) as store: + store.put("df", df, "t") + result = pd.read_hdf(store, "df", where=where) + assert_frame_equal(result, df) + class TestHDFComplexValues(Base): # GH10447