Skip to content

Read from HDF with empty where throws an error #26746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down