Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use nw.Unknown for unknown dtypes #904

Merged
merged 3 commits into from
Sep 3, 2024
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
2 changes: 1 addition & 1 deletion narwhals/_arrow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def translate_dtype(dtype: Any) -> dtypes.DType:
return dtypes.Duration()
if pa.types.is_dictionary(dtype):
return dtypes.Categorical()
raise AssertionError
return dtypes.Unknown() # pragma: no cover


def narwhals_to_native_dtype(dtype: dtypes.DType | type[dtypes.DType]) -> Any:
Expand Down
7 changes: 1 addition & 6 deletions narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ def map_duckdb_dtype_to_narwhals_dtype(
return dtypes.Boolean()
if duckdb_dtype == "INTERVAL":
return dtypes.Duration()
msg = ( # pragma: no cover
f"Invalid dtype, got: {duckdb_dtype}.\n\n"
"If you believe this dtype should be supported in Narwhals, "
"please report an issue at https://github.com/narwhals-dev/narwhals."
)
raise AssertionError(msg)
return dtypes.Unknown()


class DuckDBInterchangeFrame:
Expand Down
7 changes: 1 addition & 6 deletions narwhals/_ibis/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ def map_ibis_dtype_to_narwhals_dtype(
return dtypes.Date()
if ibis_dtype.is_timestamp():
return dtypes.Datetime()
msg = ( # pragma: no cover
f"Invalid dtype, got: {ibis_dtype}.\n\n"
"If you believe this dtype should be supported in Narwhals, "
"please report an issue at https://github.com/narwhals-dev/narwhals."
)
raise AssertionError(msg)
return dtypes.Unknown() # pragma: no cover


class IbisInterchangeFrame:
Expand Down
8 changes: 8 additions & 0 deletions tests/frame/interchange_schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta

import duckdb
import pandas as pd
import polars as pl
import pytest

Expand Down Expand Up @@ -211,3 +212,10 @@ def test_get_level() -> None:
nw.get_level(nw.from_native(df.__dataframe__(), eager_or_interchange_only=True))
== "interchange"
)


def test_unknown_dtype() -> None:
df = pd.DataFrame({"a": [1, 2, 3]})
rel = duckdb.from_df(df).select("cast(a as int128) as a")
result = nw.from_native(rel).schema
assert result == {"a": nw.Unknown}
Loading