Skip to content
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

Shadowing of variable names in Python #11945

Closed
2 tasks done
davidjbrennan opened this issue May 6, 2024 · 2 comments · Fixed by #12208
Closed
2 tasks done

Shadowing of variable names in Python #11945

davidjbrennan opened this issue May 6, 2024 · 2 comments · Fixed by #12208

Comments

@davidjbrennan
Copy link

davidjbrennan commented May 6, 2024

What happens?

In builds subsequent to 10.2, names from the duckdb module appear to be shadowing Python variables when used in queries.

To Reproduce

When I use a variable name for a dataframe in an SQL query that happens to be the name of some function in the duckdb module, I run in to the following problem. I'm using the variable name "df" in this case but I could have use "pl" or "arrow" or many other to reproduce the same error.

import pandas as pd
import duckdb

df = pd.DataFrame({"a":[1,2,3]})
duckdb.sql("from df")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/username/venv/lib/python3.12/site-packages/duckdb/__init__.py", line 455, in sql
    return conn.sql(query, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
duckdb.duckdb.InvalidInputException: Invalid Input Error: Python Object "df" of type "builtin_function_or_method" found on line "/Users/username/venv/lib/python3.12/site-packages/duckdb/__init__.py:455" not suitable for replacement scans.
Make sure that "df" is either a pandas.DataFrame, duckdb.DuckDBPyRelation, pyarrow Table, Dataset, RecordBatchReader, Scanner, or NumPy ndarrays with supported format

When I use a variable name for the dataframe that is not visible in the duckdb module then there are no problems.

pdf = df
duckdb.sql("from pdf")
┌───────┐
│   a   │
│ int64 │
├───────┤
│     1 │
│     2 │
│     3 │
└───────┘

OS:

MacOS Sonama 14.4.1 (silicon)

DuckDB Version:

0.10.3-dev777

DuckDB Client:

Python

Full Name:

David Brennan

Affiliation:

None

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a nightly build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@Tishj
Copy link
Contributor

Tishj commented May 7, 2024

Might be related to #11202 actually, since it shows up in duckdb.sql

@Mytherin
Copy link
Collaborator

Mytherin commented May 23, 2024

Can we perhaps ignore objects of type builtin_function_or_method in replacement scans entirely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants