From 0f4366743b04aa2d29986dbdfb85914841abf61b Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sat, 27 Jan 2024 06:03:58 -0500 Subject: [PATCH] fix(polars): avoid using unnecessary subquery for schema inference --- ibis/backends/polars/__init__.py | 4 +--- ibis/backends/tests/test_client.py | 2 +- ibis/backends/tests/test_dot_sql.py | 19 ++----------------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/ibis/backends/polars/__init__.py b/ibis/backends/polars/__init__.py index 15b2fcca6120..1619ac927371 100644 --- a/ibis/backends/polars/__init__.py +++ b/ibis/backends/polars/__init__.py @@ -395,9 +395,7 @@ def compile( return translate(node, ctx=ctx) def _get_schema_using_query(self, query: str) -> sch.Schema: - return schema_from_polars( - self._context.execute(f"SELECT * FROM ({query}) LIMIT 0").schema - ) + return schema_from_polars(self._context.execute(query).schema) def execute( self, diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index 4e96eb509088..ac0c8dfa4e51 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -189,7 +189,7 @@ def test_query_schema(ddl_backend, expr_fn, expected): } -@pytest.mark.notimpl(["datafusion", "polars", "mssql"]) +@pytest.mark.notimpl(["datafusion", "mssql"]) @pytest.mark.never(["dask", "pandas"], reason="dask and pandas do not support SQL") @pytest.mark.notimpl( ["flink"], raises=AttributeError, reason="'Backend' object has no attribute 'sql'" diff --git a/ibis/backends/tests/test_dot_sql.py b/ibis/backends/tests/test_dot_sql.py index df23895034ae..b5aec3ebcc95 100644 --- a/ibis/backends/tests/test_dot_sql.py +++ b/ibis/backends/tests/test_dot_sql.py @@ -33,14 +33,7 @@ @pytest.mark.parametrize( "schema", [ - param( - None, - id="implicit_schema", - marks=[ - pytest.mark.notimpl(["druid"]), - pytest.mark.notyet(["polars"], raises=PolarsComputeError), - ], - ), + param(None, id="implicit_schema", marks=[pytest.mark.notimpl(["druid"])]), param({"s": "string", "new_col": "double"}, id="explicit_schema"), ], ) @@ -82,7 +75,6 @@ def test_con_dot_sql(backend, con, schema): @dot_sql_notimpl @dot_sql_notyet @dot_sql_never -@pytest.mark.notyet(["polars"], raises=PolarsComputeError) def test_table_dot_sql(backend, con): alltypes = con.table("functional_alltypes") t = ( @@ -120,7 +112,6 @@ def test_table_dot_sql(backend, con): @dot_sql_notimpl @dot_sql_notyet @dot_sql_never -@pytest.mark.notyet(["polars"], raises=PolarsComputeError) def test_table_dot_sql_with_join(backend, con): alltypes = con.table("functional_alltypes") t = ( @@ -168,7 +159,6 @@ def test_table_dot_sql_with_join(backend, con): @dot_sql_notimpl @dot_sql_notyet @dot_sql_never -@pytest.mark.notyet(["polars"], raises=PolarsComputeError) def test_table_dot_sql_repr(con): alltypes = con.table("functional_alltypes") t = ( @@ -235,12 +225,8 @@ def test_dot_sql_reuse_alias_with_different_types(backend, alltypes, df): @pytest.mark.parametrize( "dialect", - [ - *sorted(_get_backend_names() - _NO_SQLGLOT_DIALECT), - *no_sqlglot_dialect, - ], + [*sorted(_get_backend_names() - _NO_SQLGLOT_DIALECT), *no_sqlglot_dialect], ) -@pytest.mark.notyet(["polars"], raises=PolarsComputeError) @table_dot_sql_notimpl @dot_sql_notimpl @dot_sql_notyet @@ -264,7 +250,6 @@ def test_table_dot_sql_transpile(backend, alltypes, dialect, df): *no_sqlglot_dialect, ], ) -@pytest.mark.notyet(["polars"], raises=PolarsComputeError) @pytest.mark.notyet(["druid"], raises=ValueError) @pytest.mark.notyet(["snowflake", "bigquery"]) @pytest.mark.notyet(