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

feat(python)!: Constrain access to globals from DataFrame.sql in favor of top-level pl.sql #16598

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented May 30, 2024

As discussed; updates df.sql(query) such that it can only access "self", deferring to pl.sql(query) when access to frames in the current stack is required.

This better-distinguishes the purpose of each function and allows for frame-level df.sql to be marginally optimised (as there is no longer any need to introspect globals).

Example

Before:

>>> df1 = pl.DataFrame({"id1": [1, 2]})
>>> df2 = pl.DataFrame({"id2": [3, 4]})
>>> df1.sql("SELECT * FROM df1 CROSS JOIN df2")
shape: (4, 2)
┌─────┬─────┐
│ id1 ┆ id2 │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 3   │
│ 1   ┆ 4   │
│ 2   ┆ 3   │
│ 2   ┆ 4   │
└─────┴─────┘

After:

>>> df1.sql("SELECT * FROM df1 CROSS JOIN df2")
Traceback (most recent call last):
...
polars.exceptions.SQLInterfaceError: relation 'df1' was not found

Use instead:

>>> pl.sql("SELECT * FROM df1 CROSS JOIN df2", eager=True)
shape: (4, 2)
┌─────┬─────┐
│ id1 ┆ id2 │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 3   │
│ 1   ┆ 4   │
│ 2   ┆ 3   │
│ 2   ┆ 4   │
└─────┴─────┘

@github-actions github-actions bot added breaking python Change that breaks backwards compatibility for the Python package internal An internal refactor or improvement python Related to Python Polars labels May 30, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label May 30, 2024
@stinodego stinodego changed the title chore(python!): Constrain access to globals from df.sql in favour of top-level pl.sql feat(python)!: Constrain access to globals from df.sql in favour of top-level pl.sql May 30, 2024
@stinodego stinodego removed internal An internal refactor or improvement breaking python Change that breaks backwards compatibility for the Python package labels May 30, 2024
@github-actions github-actions bot added breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature labels May 30, 2024
@stinodego stinodego added this to the 1.0.0 milestone May 30, 2024
@alexander-beedie alexander-beedie merged commit ce0bea2 into pola-rs:main Jun 4, 2024
16 checks passed
@alexander-beedie alexander-beedie deleted the adjust-sql-methods branch June 4, 2024 09:06
@stinodego stinodego changed the title feat(python)!: Constrain access to globals from df.sql in favour of top-level pl.sql feat(python)!: Constrain access to globals from df.sql in favor of top-level pl.sql Jun 12, 2024
@stinodego stinodego changed the title feat(python)!: Constrain access to globals from df.sql in favor of top-level pl.sql feat(python)!: Constrain access to globals from DataFrame.sql in favor of top-level pl.sql Jun 12, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: Polars SQL functionality breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants