-
-
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
Conversation
where
throws an error
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -649,6 +649,7 @@ I/O | |||
- Bug in :func:`read_json` where date strings with ``Z`` were not converted to a UTC timezone (:issue:`26168`) | |||
- 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`) | |||
- Bug while selecting from HDF store with `where`='' specified (:issue:`26610`). Now the whole DataFrame will be returned from store. |
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`
, put where=''
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.
pandas/io/pytables.py
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is connected with next request. Check it please.
pandas/io/pytables.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
you can just do
where if where else None
as bool('') and bool([]) evaluate to False
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.
I did id at first, but in case some input where
is some valid expression as string - get after elif
where
as Index
. So this comparsion throws an The truth value of a Int64Index is ambiguous
.
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.
then just do
return where if len(where) else None
pandas/tests/io/test_pytables.py
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified.
pandas/tests/io/test_pytables.py
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -649,6 +649,7 @@ I/O | |||
- Bug in :func:`read_json` where date strings with ``Z`` were not converted to a UTC timezone (:issue:`26168`) | |||
- 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`) | |||
- Bug while selecting from :class: `pandas.HDFstore` with `where=''` specified (:issue:`26610`). |
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.
no space in :class:`HDFStore`
(also spelling), use double-backticks around where
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.
Done. Check please. Sorry - have never worked with .rst
before.
pandas/io/pytables.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
then just do
return where if len(where) else None
Codecov Report
@@ Coverage Diff @@
## master #26746 +/- ##
=======================================
Coverage 91.7% 91.7%
=======================================
Files 179 179
Lines 50767 50767
=======================================
Hits 46555 46555
Misses 4212 4212
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26746 +/- ##
==========================================
- Coverage 91.71% 91.71% -0.01%
==========================================
Files 178 178
Lines 50776 50776
==========================================
- Hits 46571 46567 -4
- Misses 4205 4209 +4
Continue to review full report at Codecov.
|
|
In one of the tests the Besides I'm confused with type checking - now |
lgtm. can you merge master and ping on green. |
I'm sorry - what is "ping on green"? |
ping on green - when the CI is green where=‘’ is the same as where=None so yes return the entire frame |
@jreback all is green. |
thanks @BeforeFlight |
where
throws an error #26610git diff upstream/master -u -- "*.py" | flake8 --diff