Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions narwhals/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ def _import_native_namespace(module_name: str) -> ModuleType:
def backend_version(implementation: Implementation, /) -> tuple[int, ...]:
if not isinstance(implementation, Implementation):
assert_never(implementation)
if implementation is Implementation.UNKNOWN: # pragma: no cover
msg = "Cannot return backend version from UNKNOWN Implementation"
raise AssertionError(msg)
if implementation is Implementation.UNKNOWN:
return (0, 0, 0)
into_version: ModuleType | str
impl = implementation
module_name = _IMPLEMENTATION_TO_MODULE_NAME.get(impl, impl.value)
Expand Down
17 changes: 17 additions & 0 deletions tests/dependencies/imports_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ def test_to_native_namespace_unknown() -> None:
AssertionError, match="Cannot return native namespace from UNKNOWN Implementation"
):
impl.to_native_namespace()


@pytest.mark.parametrize("impl", list(Implementation))
def test_backend_version(impl: Implementation) -> None:
version: tuple[int, ...] | None
try:
version = impl._backend_version()
except (ModuleNotFoundError, ValueError) as err:
# NOTE: See https://github.com/narwhals-dev/narwhals/issues/2786
assert impl is not Implementation.UNKNOWN

with pytest.raises(type(err)):
impl.to_native_namespace()
version = None

if version is not None:
assert version >= (0, 0, 0)
Loading