Skip to content

Commit

Permalink
feat: autopolars support (#170)
Browse files Browse the repository at this point in the history
A new feature of jupysql 0.7
  • Loading branch information
eitsupi committed Apr 15, 2023
1 parent 0e4a62f commit db3edf3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
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
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
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
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
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

0 comments on commit db3edf3

Please sign in to comment.