question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve `DataFrame.query` docstring with local variable example

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
umonacacommented, Sep 24, 2021

I’ll look into it tomorrow.

0reactions
jsignellcommented, Oct 4, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found