Skip to content

Commit

Permalink
chore: deprecate register api
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi committed Apr 2, 2024
1 parent 9dabae0 commit df9b8ad
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
6 changes: 5 additions & 1 deletion ibis/backends/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ibis.backends.sql.compiler import C
from ibis.expr.operations.udf import InputType
from ibis.formats.pyarrow import PyArrowType
from ibis.util import gen_name, normalize_filename
from ibis.util import deprecated, gen_name, normalize_filename

Check warning on line 29 in ibis/backends/datafusion/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/__init__.py#L29

Added line #L29 was not covered by tests

try:
from datafusion import ExecutionContext as SessionContext
Expand Down Expand Up @@ -294,6 +294,10 @@ def get_schema(
table = database.table(table_name)
return sch.schema(table.schema)

@deprecated(

Check warning on line 297 in ibis/backends/datafusion/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/__init__.py#L297

Added line #L297 was not covered by tests
as_of="9.0",
instead="use the explicit `read_*` method for the filetype you are trying to read, e.g., read_parquet, read_csv, etc.",
)
def register(
self,
source: str | Path | pa.Table | pa.RecordBatch | pa.Dataset | pd.DataFrame,
Expand Down
20 changes: 12 additions & 8 deletions ibis/backends/datafusion/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ def test_read_parquet(conn, data_dir):

def test_register_table(conn):
tab = pa.table({"x": [1, 2, 3]})
conn.register(tab, "my_table")
assert conn.table("my_table").x.sum().execute() == 6
with pytest.warns(FutureWarning, match="v9.0"):
conn.register(tab, "my_table")
assert conn.table("my_table").x.sum().execute() == 6

Check warning on line 30 in ibis/backends/datafusion/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/tests/test_register.py#L29-L30

Added lines #L29 - L30 were not covered by tests


def test_register_pandas(conn):
df = pd.DataFrame({"x": [1, 2, 3]})
conn.register(df, "my_table")
assert conn.table("my_table").x.sum().execute() == 6
with pytest.warns(FutureWarning, match="v9.0"):
conn.register(df, "my_table")
assert conn.table("my_table").x.sum().execute() == 6

Check warning on line 37 in ibis/backends/datafusion/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/tests/test_register.py#L36-L37

Added lines #L36 - L37 were not covered by tests


def test_register_batches(conn):
batch = pa.record_batch([pa.array([1, 2, 3])], names=["x"])
conn.register(batch, "my_table")
assert conn.table("my_table").x.sum().execute() == 6
with pytest.warns(FutureWarning, match="v9.0"):
conn.register(batch, "my_table")
assert conn.table("my_table").x.sum().execute() == 6

Check warning on line 44 in ibis/backends/datafusion/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/tests/test_register.py#L43-L44

Added lines #L43 - L44 were not covered by tests


def test_register_dataset(conn):
tab = pa.table({"x": [1, 2, 3]})
dataset = ds.InMemoryDataset(tab)
conn.register(dataset, "my_table")
assert conn.table("my_table").x.sum().execute() == 6
with pytest.warns(FutureWarning, match="v9.0"):
conn.register(dataset, "my_table")
assert conn.table("my_table").x.sum().execute() == 6

Check warning on line 52 in ibis/backends/datafusion/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/datafusion/tests/test_register.py#L51-L52

Added lines #L51 - L52 were not covered by tests
5 changes: 5 additions & 0 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compiler import STAR, C, F
from ibis.expr.operations.udf import InputType
from ibis.util import deprecated

Check warning on line 32 in ibis/backends/duckdb/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/__init__.py#L32

Added line #L32 was not covered by tests

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
Expand Down Expand Up @@ -515,6 +516,10 @@ def drop_database(
with self._safe_raw_sql(sge.Drop(this=name, kind="SCHEMA", replace=force)):
pass

@deprecated(

Check warning on line 519 in ibis/backends/duckdb/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/__init__.py#L519

Added line #L519 was not covered by tests
as_of="9.0",
instead="use the explicit `read_*` method for the filetype you are trying to read, e.g., read_parquet, read_csv, etc.",
)
def register(
self,
source: str | Path | Any,
Expand Down
11 changes: 6 additions & 5 deletions ibis/backends/duckdb/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,13 @@ def test_read_sqlite_no_table_name(con, tmp_path):
raises=duckdb.IOException,
)
def test_register_sqlite(con, tmp_path):
path = tmp_path / "test.db"
with pytest.warns(FutureWarning, match="v9.0"):
path = tmp_path / "test.db"

Check warning on line 260 in ibis/backends/duckdb/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/tests/test_register.py#L260

Added line #L260 was not covered by tests

sqlite_con = sqlite3.connect(str(path))
sqlite_con.execute("CREATE TABLE t AS SELECT 1 a UNION SELECT 2 UNION SELECT 3")
ft = con.register(f"sqlite://{path}", "t")
assert ft.count().execute()
sqlite_con = sqlite3.connect(str(path))
sqlite_con.execute("CREATE TABLE t AS SELECT 1 a UNION SELECT 2 UNION SELECT 3")
ft = con.register(f"sqlite://{path}", "t")
assert ft.count().execute()

Check warning on line 265 in ibis/backends/duckdb/tests/test_register.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/tests/test_register.py#L262-L265

Added lines #L262 - L265 were not covered by tests


# Because we create a new connection and the test requires loading/installing a
Expand Down
6 changes: 5 additions & 1 deletion ibis/backends/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ibis.backends.sql.dialects import Polars
from ibis.expr.rewrites import rewrite_stringslice
from ibis.formats.polars import PolarsSchema
from ibis.util import gen_name, normalize_filename
from ibis.util import deprecated, gen_name, normalize_filename

Check warning on line 25 in ibis/backends/polars/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/polars/__init__.py#L25

Added line #L25 was not covered by tests

if TYPE_CHECKING:
from collections.abc import Iterable
Expand Down Expand Up @@ -74,6 +74,10 @@ def table(self, name: str, _schema: sch.Schema | None = None) -> ir.Table:
schema = PolarsSchema.to_ibis(self._tables[name].schema)
return ops.DatabaseTable(name, schema, self).to_expr()

@deprecated(

Check warning on line 77 in ibis/backends/polars/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/polars/__init__.py#L77

Added line #L77 was not covered by tests
as_of="9.0",
instead="use the explicit `read_*` method for the filetype you are trying to read, e.g., read_parquet, read_csv, etc.",
)
def register(
self,
source: str | Path | Any,
Expand Down
5 changes: 5 additions & 0 deletions ibis/backends/pyspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ibis.backends.sql import SQLBackend
from ibis.expr.operations.udf import InputType
from ibis.legacy.udf.vectorized import _coerce_to_series
from ibis.util import deprecated

Check warning on line 28 in ibis/backends/pyspark/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/__init__.py#L28

Added line #L28 was not covered by tests

if TYPE_CHECKING:
from collections.abc import Mapping, Sequence
Expand Down Expand Up @@ -649,6 +650,10 @@ def read_json(
spark_df.createOrReplaceTempView(table_name)
return self.table(table_name)

@deprecated(

Check warning on line 653 in ibis/backends/pyspark/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/__init__.py#L653

Added line #L653 was not covered by tests
as_of="9.0",
instead="use the explicit `read_*` method for the filetype you are trying to read, e.g., read_parquet, read_csv, etc.",
)
def register(
self,
source: str | Path | Any,
Expand Down

0 comments on commit df9b8ad

Please sign in to comment.