Skip to content

Commit

Permalink
refactor: utilize narwhals fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Feb 5, 2025
1 parent 193fabd commit 6c93eb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
18 changes: 2 additions & 16 deletions altair/datasets/_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

import functools
import operator
from collections.abc import Set
from itertools import chain
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -61,23 +59,11 @@ def collect(**kwds: Unpack[Metadata]) -> Metadata:
return dict(self)

def to_expr(self) -> nw.Expr:
"""
Convert constraint into a narhwals expression.
Notes
-----
Workaround for `issue`_ is performing the reduction with ``stdlib``
.. _issue:
https://github.com/narwhals-dev/narwhals/issues/1897
.. _discussion:
https://github.com/vega/altair/pull/3631#discussion_r1934313255
"""
"""Convert constraint into a narwhals expression."""
if not self:
msg = f"Unable to convert an empty set to an expression:\n\n{self!r}"
raise TypeError(msg)
exprs = (nw.col(name) == val for name, val in self)
return functools.reduce(operator.and_, exprs)
return nw.all_horizontal(nw.col(name) == val for name, val in self)

def isdisjoint(self, other: Iterable[Any]) -> bool:
return super().isdisjoint(other)
Expand Down
3 changes: 1 addition & 2 deletions altair/datasets/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ def profile(self, *, show: bool = False) -> _SupportProfile | None:
chain.from_iterable(impl._relevant_columns for impl in self._read)
)
frame = self._scan_metadata().select("dataset_name", *relevant_columns)
it = (impl._include_expr for impl in self._read)
inc_expr = nw.any_horizontal(*it)
inc_expr = nw.any_horizontal(impl._include_expr for impl in self._read)
result: _SupportProfile = {
"unsupported": _dataset_names(frame, ~inc_expr),
"supported": _dataset_names(frame, inc_expr),
Expand Down

0 comments on commit 6c93eb0

Please sign in to comment.