Improve `DataFrame.query` docstring with local variable example
See original GitHub issueWhat happened: Prepare Dask distributed:
from dask.distributed import Client
client = Client(n_workers=16,
threads_per_worker=1)
This works:
import pandas as pd
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
df = pd.DataFrame.from_dict(data)
pick = 'c'
df.query('col_2 == @pick')
This doesn’t work:
dd_temp = dd.from_pandas(df, npartitions=2)
dd_temp.query('col_2 == @pick')
Throws UndefinedVariableError(“local variable ‘pick’ is not defined”).
What you expected to happen: Dask version of DataFrame.query should work as in pandas.
Minimal Complete Verifiable Example: See above
Anything else we need to know?: No
Environment:
- Dask version: 2021.8.0
- Python version: 3.9.6
- Operating System: Linux (Manjaro)
- Install method (conda, pip, source): conda-forge
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Docstring for variable - python - Stack Overflow
Use typing.Annotated to provide a docstring for variables. I originally wrote an answer (see below) where I said this wasn't possible.
Read more >pandas.DataFrame.query — pandas 1.5.2 documentation
Query the columns of a DataFrame with a boolean expression. Parameters. exprstr. The query string to evaluate. You can refer to variables in...
Read more >Writing Functions In Python - Hylke Rozema
Copy the following string and add it as the docstring for the function: Count the number of times `letter` appears in `content`.
Read more >Get More Efficient in your Data Analysis with Pandas `query ...
This involves writing expression by creating a mask which is then passed to the DataFrame as shown below in an example:
Read more >Pandas DataFrame .query() method with Python 3.6+ f-strings
This toy example is just to show the chaining principle. Cool use of @ to reference local variables. Turns out you can use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll look into it tomorrow.
Ohh! That’s true https://docs.dask.org/en/latest/generated/dask.dataframe.DataFrame.query.html is very thin! I only realized that pattern was supported because I was looking around in the tests. Please feel free to open a pull request with an example of that pattern @umonaca!