From 8a9535f43af953c82213b8f3ff3c6b7e0eb41f16 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Tue, 2 Jul 2024 10:28:07 -0500 Subject: [PATCH] fix(pandas, dask): fix `drop_table` handling of `force` keyword --- ibis/backends/pandas/__init__.py | 10 +++++----- ibis/backends/tests/test_client.py | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ibis/backends/pandas/__init__.py b/ibis/backends/pandas/__init__.py index 646bb0c49764..ce44a6b4f0f3 100644 --- a/ibis/backends/pandas/__init__.py +++ b/ibis/backends/pandas/__init__.py @@ -237,11 +237,11 @@ def drop_view(self, name: str, *, force: bool = False) -> None: self.drop_table(name, force=force) def drop_table(self, name: str, *, force: bool = False) -> None: - if not force and name in self.dictionary: - raise com.IbisError( - "Cannot drop existing table. Call drop_table with force=True to drop existing table." - ) - del self.dictionary[name] + try: + del self.dictionary[name] + except KeyError: + if not force: + raise com.IbisError(f"Table {name} does not exist") from None def _convert_object(self, obj: Any) -> Any: return _convert_object(obj, self) diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index 5bfd29f52d7d..cf5b26e7dca2 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -1024,9 +1024,7 @@ def test_create_table_in_memory(con, obj, table_name, monkeypatch): assert result.equals(t.to_pyarrow()) - with contextlib.suppress(NotImplementedError): - # polars doesn't have drop_table - con.drop_table(table_name, force=True) + con.drop_table(table_name, force=True) def test_default_backend_option(con, monkeypatch):