Skip to content

Commit

Permalink
test(duckdb): ensure that no test causes the default backend to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and jcrist committed Jan 4, 2024
1 parent da04679 commit d8360ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
38 changes: 17 additions & 21 deletions ibis/backends/duckdb/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
import sqlalchemy as sa

import ibis
import ibis.common.exceptions as exc
import ibis.expr.datatypes as dt
from ibis.conftest import LINUX, SANDBOXED


def test_read_csv(data_dir):
t = ibis.read_csv(data_dir / "csv" / "functional_alltypes.csv")
def test_read_csv(con, data_dir):
t = con.read_csv(data_dir / "csv" / "functional_alltypes.csv")
assert t.count().execute()


def test_read_csv_with_columns(data_dir):
t = ibis.read_csv(
def test_read_csv_with_columns(con, data_dir):
t = con.read_csv(
data_dir / "csv" / "awards_players.csv",
header=True,
columns={
Expand All @@ -41,8 +40,8 @@ def test_read_csv_with_columns(data_dir):
assert t.count().execute()


def test_read_parquet(data_dir):
t = ibis.read_parquet(data_dir / "parquet" / "functional_alltypes.parquet")
def test_read_parquet(con, data_dir):
t = con.read_parquet(data_dir / "parquet" / "functional_alltypes.parquet")
assert t.count().execute()


Expand Down Expand Up @@ -122,16 +121,13 @@ def test_read_geo_from_url(con, monkeypatch):
assert "httpfs" in loaded_exts


@pytest.mark.xfail_version(
duckdb=["duckdb<0.7.0"], reason="read_json_auto doesn't exist", raises=exc.IbisError
)
def test_read_json(data_dir, tmp_path):
pqt = ibis.read_parquet(data_dir / "parquet" / "functional_alltypes.parquet")
def test_read_json(con, data_dir, tmp_path):
pqt = con.read_parquet(data_dir / "parquet" / "functional_alltypes.parquet")

path = tmp_path.joinpath("ft.json")
path.write_text(pqt.execute().to_json(orient="records", lines=True))

jst = ibis.read_json(path)
jst = con.read_json(path)

nrows = pqt.count().execute()
assert nrows
Expand Down Expand Up @@ -301,7 +297,7 @@ def test_re_read_in_memory_overwrite(con):
assert table.schema() == ibis.schema([("a", "int"), ("c", "float")])


def test_memtable_with_nullable_dtypes():
def test_memtable_with_nullable_dtypes(con):
data = pd.DataFrame(
{
"a": pd.Series(["a", None, "c"], dtype="string"),
Expand All @@ -317,19 +313,19 @@ def test_memtable_with_nullable_dtypes():
}
)
expr = ibis.memtable(data)
res = expr.execute()
res = con.execute(expr)
assert len(res) == len(data)


def test_memtable_with_nullable_pyarrow_string():
def test_memtable_with_nullable_pyarrow_string(con):
pytest.importorskip("pyarrow")
data = pd.DataFrame({"a": pd.Series(["a", None, "c"], dtype="string[pyarrow]")})
expr = ibis.memtable(data)
res = expr.execute()
res = con.execute(expr)
assert len(res) == len(data)


def test_memtable_with_nullable_pyarrow_not_string():
def test_memtable_with_nullable_pyarrow_not_string(con):
pytest.importorskip("pyarrow")

data = pd.DataFrame(
Expand All @@ -346,7 +342,7 @@ def test_memtable_with_nullable_pyarrow_not_string():
}
)
expr = ibis.memtable(data)
res = expr.execute()
res = con.execute(expr)
assert len(res) == len(data)


Expand Down Expand Up @@ -447,7 +443,7 @@ def test_register_filesystem_gcs(con):

def test_memtable_null_column_parquet_dtype_roundtrip(con, tmp_path):
before = ibis.memtable({"a": [None, None, None]}, schema={"a": "string"})
before.to_parquet(tmp_path / "tmp.parquet")
after = ibis.read_parquet(tmp_path / "tmp.parquet")
con.to_parquet(before, tmp_path / "tmp.parquet")
after = con.read_parquet(tmp_path / "tmp.parquet")

assert before.a.type() == after.a.type()
10 changes: 7 additions & 3 deletions ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,14 @@ def test_create_from_in_memory_table(con, temp_table, arg, func, monkeypatch):


@pytest.mark.usefixtures("backend")
def test_default_backend_option(monkeypatch):
monkeypatch.setattr(ibis.options, "default_backend", ibis.pandas)
def test_default_backend_option(con, monkeypatch):
# verify that there's nothing already set
assert ibis.options.default_backend is None

monkeypatch.setattr(ibis.options, "default_backend", con)

backend = ibis.config._default_backend()
assert backend.name == "pandas"
assert backend.name == con.name


# backend is used to ensure that this test runs in CI in the setting
Expand Down

0 comments on commit d8360ab

Please sign in to comment.