Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jun 5, 2024
1 parent c7c7cfd commit 6027482
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/sql/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ def execute_global(
possible_names = {
nm
for nm in re.split(r"\s", q)
if re.match(r'^("[^"]+"|\w+)$', nm) and nm.lower() not in _SQL_KEYWORDS_
if re.match(r'^("[^"]+")$', nm)
or (nm.isidentifier() and nm.lower() not in _SQL_KEYWORDS_)
}

# get compatible frame objects from the globals, constraining by possible names
named_frames = _get_frame_locals(all_compatible=True, named=possible_names)
with cls(frames=named_frames, register_globals=False) as ctx:
Expand Down
21 changes: 10 additions & 11 deletions py-polars/polars/sql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def sql(query: str, *, eager: bool = False) -> DataFrame | LazyFrame:
.. versionadded:: 0.20.31
Notes
-----
The Polars SQL engine can operate against Polars DataFrame, LazyFrame, and Series
objects, as well as Pandas DataFrame and Series, and PyArrow Table and RecordBatch.
Parameters
----------
query
Expand All @@ -35,6 +30,8 @@ def sql(query: str, *, eager: bool = False) -> DataFrame | LazyFrame:
Notes
-----
* The Polars SQL engine can operate against Polars DataFrame, LazyFrame, and Series
objects, as well as Pandas DataFrame and Series, PyArrow Table and RecordBatch.
* Additional control over registration and execution behaviour is available
with the :class:`SQLContext` object.
Expand Down Expand Up @@ -113,12 +110,14 @@ def sql(query: str, *, eager: bool = False) -> DataFrame | LazyFrame:
... [pa.array([1, 2, 3]), pa.array(["x", "y", "z"])],
... names=["a", "e"],
... )
>>> pl.sql('''
... SELECT pl_frame.*, d, e
... FROM pl_frame
... JOIN pd_frame USING(a)
... JOIN pa_table USING(a)
... ''').collect()
>>> pl.sql(
... query='''
... SELECT pl_frame.*, d, e
... FROM pl_frame
... JOIN pd_frame USING(a)
... JOIN pa_table USING(a)
... ''',
... ).collect()
shape: (2, 5)
┌─────┬─────┬─────┬──────┬─────┐
│ a ┆ b ┆ c ┆ d ┆ e │
Expand Down
6 changes: 0 additions & 6 deletions py-polars/tests/unit/sql/test_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,3 @@ def test_intervals() -> None:
match="minus signs are not yet supported in interval strings; found '-7d'",
):
ctx.execute("SELECT INTERVAL '-7d' AS one_week_ago FROM df")

with pytest.raises(
SQLSyntaxError,
match="unary ops are not valid on interval strings; found -'7d'",
):
ctx.execute("SELECT INTERVAL -'7d' AS one_week_ago FROM df")

0 comments on commit 6027482

Please sign in to comment.