From 4b34a61b54ef6aed678f8241c23667c8ddf7e474 Mon Sep 17 00:00:00 2001 From: Daniel Mesejo Date: Fri, 27 Sep 2024 15:36:54 +0200 Subject: [PATCH] feat: add get_backend to expr (#10228) --- ibis/backends/tests/test_api.py | 5 +++++ ibis/expr/types/core.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/ibis/backends/tests/test_api.py b/ibis/backends/tests/test_api.py index 108a194ecb0c..b75c99d8c28c 100644 --- a/ibis/backends/tests/test_api.py +++ b/ibis/backends/tests/test_api.py @@ -136,3 +136,8 @@ def test_unbind(alltypes, expr_fn): assert "Unbound" not in repr(expr) assert "Unbound" in repr(expr.unbind()) + + +def test_get_backend(con, alltypes): + assert alltypes.get_backend() is con + assert alltypes.id.min().get_backend() is con diff --git a/ibis/expr/types/core.py b/ibis/expr/types/core.py index 9c9c380b114e..27ccbc2e5c08 100644 --- a/ibis/expr/types/core.py +++ b/ibis/expr/types/core.py @@ -375,6 +375,17 @@ def _find_backend(self, *, use_default: bool = False) -> BaseBackend: return backends[0] + def get_backend(self): + """Get the current Ibis backend of the expression. + + Returns + ------- + BaseBackend + The Ibis backend. + + """ + return self._find_backend(use_default=True) + def execute( self, limit: int | str | None = "default",