diff --git a/altair/utils/core.py b/altair/utils/core.py index acc7c2810..9143a1ec5 100644 --- a/altair/utils/core.py +++ b/altair/utils/core.py @@ -709,11 +709,14 @@ def infer_vegalite_type_for_narwhals( and not (categories := column.cat.get_categories()).is_empty() ): return "ordinal", categories.to_list() - if dtype in {nw.String, nw.Categorical, nw.Boolean}: + if dtype == nw.String or dtype == nw.Categorical or dtype == nw.Boolean: # noqa: PLR1714 return "nominal" elif dtype.is_numeric(): return "quantitative" - elif dtype in {nw.Datetime, nw.Date}: + elif dtype == nw.Datetime or dtype == nw.Date: # noqa: PLR1714 + # We use `== nw.Datetime` to check for any kind of Datetime, regardless of time + # unit and time zone. Prefer this over `dtype in {nw.Datetime, nw.Date}`, + # see https://narwhals-dev.github.io/narwhals/backcompat. return "temporal" else: msg = f"Unexpected DtypeKind: {dtype}" diff --git a/tests/test_transformed_data.py b/tests/test_transformed_data.py index ee689ff68..1196c7b07 100644 --- a/tests/test_transformed_data.py +++ b/tests/test_transformed_data.py @@ -7,7 +7,7 @@ import altair as alt from altair.utils.execeval import eval_block from tests import examples_methods_syntax, slow, ignore_DataFrameGroupBy -import narwhals as nw +import narwhals.stable.v1 as nw try: import vegafusion as vf