Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ python = "^3.8"

duckdb-engine = "^0.7"
ipython = "^8"
jupysql = ">=0.6"
jupysql = ">=0.7"
pandas = ">=1.5"
prql-python = "^0.8"
traitlets = "^5"
Expand Down Expand Up @@ -54,6 +54,7 @@ ruff = "^0.0.225"
safety = "^2"
sphinx-rtd-theme = "^1.0.0"
xdoctest = "^0.15.10"
polars = ">=0.16"

[tool.poetry.scripts]
pyprql = "pyprql.cli.__init__:main"
Expand Down
7 changes: 7 additions & 0 deletions pyprql/magic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ PrqlMagic.autolimit=<Int>
PrqlMagic.autopandas=<Bool>
Return Pandas DataFrames instead of regular result sets
Current: True
PrqlMagic.autopolars=<Bool>
Return Polars DataFrames instead of regular result sets
Current: False
PrqlMagic.autoview=<Bool>
Display results
Current: True
Expand All @@ -183,6 +186,10 @@ PrqlMagic.dsn_filename=<Unicode>
PrqlMagic.feedback=<Bool>
Print number of rows affected by DML
Current: False
PrqlMagic.polars_dataframe_kwargs=<key-1>=<value-1>...
Polars DataFrame constructor keyword arguments(e.g. infer_schema_length,
nan_to_null, schema_overrides, etc)
Current: {}
PrqlMagic.short_errors=<Bool>
Don't display the full traceback on SQL Programming Error
Current: True
Expand Down
5 changes: 5 additions & 0 deletions pyprql/magic/prql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class PrqlMagic(SqlMagic):
config=True,
help="Return Pandas DataFrames instead of regular result sets",
)
autopolars = Bool(
False,
config=True,
help="Return Polars DataFrames instead of regular result sets",
)
autoview = Bool(True, config=True, help="Display results")
feedback = Bool(False, config=True, help="Print number of rows affected by DML")
target = Unicode("sql.any", config=True, help="Compile target of prql-compiler")
Expand Down
12 changes: 11 additions & 1 deletion pyprql/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import tempfile
from textwrap import dedent

import polars as pl
import pytest
from sqlalchemy import create_engine

Expand Down Expand Up @@ -262,13 +263,22 @@ def test_bind_vars(ip):


def test_autopandas(ip):
ip.run_line_magic("config", "SqlMagic.autopandas = True")
dframe = run_prql(ip, "from test")
assert not dframe.empty
assert dframe.ndim == 2
assert dframe.name[0] == "foo"


def test_autopolars(ip):
ip.run_line_magic("config", "PrqlMagic.autopolars = True")
dframe = run_prql(ip, "from test")

assert type(dframe) == pl.DataFrame
assert not dframe.is_empty()
assert len(dframe.shape) == 2
assert dframe["name"][0] == "foo"


def test_target_dialect(ip):
ip.run_line_magic("config", 'PrqlMagic.target = "sql.sqlite"')
dframe = run_prql(
Expand Down