Skip to content

Commit

Permalink
chore: use more robust dtype comparisons, use Narwhals stable API in …
Browse files Browse the repository at this point in the history
…tests (vega#3670)
  • Loading branch information
MarcoGorelli authored Nov 3, 2024
1 parent 88c76e3 commit 613b6e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transformed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 613b6e4

Please sign in to comment.