-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 1 commit
e55f060
a7f0ad2
3b2a5c0
f75ae8c
8ae2517
89245dc
59a6815
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,10 +95,10 @@ def _ensure_term(where, scope_level): | |
wlist.append(w) | ||
else: | ||
wlist.append(Term(w, scope_level=level)) | ||
where = wlist | ||
where = wlist if wlist else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is connected with next request. Check it please. |
||
elif maybe_expression(where): | ||
where = Term(where, scope_level=level) | ||
return where | ||
return where if where != "" else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did id at first, but in case some input There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then just do
|
||
|
||
|
||
class PossibleDataLossError(Exception): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4731,6 +4731,34 @@ def test_read_py2_hdf_file_in_py3(self, datapath): | |
result = store['p'] | ||
assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("call", [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not necessary to parameterize over the method calls, read_hdf is enough There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified. |
||
"read_hdf", "select", "select_as_coordinates", "select_as_multiple" | ||
]) | ||
@pytest.mark.parametrize("where", ["", (), (None, ), [], [None]]) | ||
def test_select_empty_where(self, call, 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], [1, 2]], columns=list("ab")) | ||
with ensure_clean_path("empty_where.h5") as path: | ||
with pd.HDFStore(path) as store: | ||
key1 = "df1" | ||
key2 = "df2" | ||
store.put("df1", df[["a"]], "t") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use result = read_hdf(....) assert_frame_equal(result, df) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
store.put("df2", df[["b"]], "t") | ||
if call == "read_hdf": | ||
pd.read_hdf(store, key1, where=where) | ||
elif call == "select": | ||
store.select(key1, where=where) | ||
elif call == "select_as_coordinates": | ||
store.select_as_coordinates(key1, where=where) | ||
elif call == "select_as_multiple": | ||
store.select_as_multiple( | ||
[key1, key2], where=where, selector=key1) | ||
|
||
|
||
class TestHDFComplexValues(Base): | ||
# GH10447 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
:class`HDFStore`
, putwhere=''
in double backtikcs. Don't put anything after the issue number (e.g. remove the Now the whole DataFrame ...), you can put that before if you want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check please - not sure if I get
:class
correctly.