Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into interactive_tooltip…
Browse files Browse the repository at this point in the history
…_legend
  • Loading branch information
dangotbanned committed Aug 25, 2024
2 parents bd7ccfb + bf7fc29 commit 4b12df6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ def _deep_copy(obj: Any, by_ref: set[str]) -> Any: ...
def _deep_copy(obj: _CopyImpl | Any, by_ref: set[str]) -> _CopyImpl | Any:
copy = partial(_deep_copy, by_ref=by_ref)
if isinstance(obj, SchemaBase):
if copier := getattr(obj, "__deepcopy__", None):
with debug_mode(False):
return copier(obj)
args = (copy(arg) for arg in obj._args)
kwds = {k: (copy(v) if k not in by_ref else v) for k, v in obj._kwds.items()}
with debug_mode(False):
Expand Down
3 changes: 3 additions & 0 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,9 @@ def to_dict(self, *args: Any, **kwds: Any) -> _Conditional[_C]: # type: ignore[
m = super().to_dict(*args, **kwds)
return _Conditional(condition=m["condition"])

def __deepcopy__(self, memo: Any) -> Self:
return type(self)(_Conditional(condition=_deepcopy(self.condition)))


class ChainedWhen(_BaseWhen):
"""
Expand Down
21 changes: 21 additions & 0 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,27 @@ def test_when_condition_parity(
assert chart_condition == chart_when


def test_when_then_interactive() -> None:
"""Copy-related regression found in https://github.com/vega/altair/pull/3394#issuecomment-2302995453."""
source = "https://cdn.jsdelivr.net/npm/[email protected]/data/movies.json"
predicate = (alt.datum.IMDB_Rating == None) | ( # noqa: E711
alt.datum.Rotten_Tomatoes_Rating == None # noqa: E711
)

chart = (
alt.Chart(source)
.mark_point(invalid=None)
.encode(
x="IMDB_Rating:Q",
y="Rotten_Tomatoes_Rating:Q",
color=alt.when(predicate).then(alt.value("grey")), # type: ignore[arg-type]
)
)
assert chart.interactive()
assert chart.copy()
assert chart.to_dict()


def test_selection_to_dict():
brush = alt.selection_interval()

Expand Down
3 changes: 3 additions & 0 deletions tools/schemapi/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@ def _deep_copy(obj: Any, by_ref: set[str]) -> Any: ...
def _deep_copy(obj: _CopyImpl | Any, by_ref: set[str]) -> _CopyImpl | Any:
copy = partial(_deep_copy, by_ref=by_ref)
if isinstance(obj, SchemaBase):
if copier := getattr(obj, "__deepcopy__", None):
with debug_mode(False):
return copier(obj)
args = (copy(arg) for arg in obj._args)
kwds = {k: (copy(v) if k not in by_ref else v) for k, v in obj._kwds.items()}
with debug_mode(False):
Expand Down

0 comments on commit 4b12df6

Please sign in to comment.