Skip to content

Commit

Permalink
fix(backend): read the default backend setting in _default_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jan 12, 2023
1 parent 62e68da commit 11252af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 10 additions & 0 deletions ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,16 @@ def test_create_from_in_memory_table(backend, con, t):
assert tmp_name not in con.list_tables()


def test_default_backend_option():
orig = ibis.options.default_backend
ibis.options.default_backend = ibis.pandas
try:
backend = ibis.config._default_backend()
assert backend.name == "pandas"
finally:
ibis.options.default_backend = orig


def test_default_backend_no_duckdb(backend):
# backend is used to ensure that this test runs in CI in the setting
# where only the dependencies for a a given backend are installed
Expand Down
18 changes: 4 additions & 14 deletions ibis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,19 @@ class Options(Config):
pyspark: Optional[Config] = None


_HAS_DUCKDB = True
_DUCKDB_CON = None


def _default_backend() -> Any:
global _HAS_DUCKDB, _DUCKDB_CON

if not _HAS_DUCKDB:
return None

if _DUCKDB_CON is not None:
return _DUCKDB_CON
if (backend := options.default_backend) is not None:
return backend

try:
import duckdb as _ # noqa: F401
except ImportError:
_HAS_DUCKDB = False
return None

import ibis

_DUCKDB_CON = ibis.duckdb.connect(":memory:")
return _DUCKDB_CON
options.default_backend = con = ibis.duckdb.connect(":memory:")
return con


options = Options()
Expand Down

0 comments on commit 11252af

Please sign in to comment.