Skip to content

Commit

Permalink
refactor: reduce code duplication in Chart.to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Jul 16, 2024
1 parent 222f953 commit 419a4e9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
AggregateOp_T,
MultiTimeUnit_T,
SingleTimeUnit_T,
Map,
)

ChartDataType: TypeAlias = Optional[Union[DataType, core.Data, str, core.Generator]]
Expand Down Expand Up @@ -2987,17 +2988,14 @@ def to_dict(
if validate=True and the dict does not conform to the schema
"""
context = context or {}
kwds: Map = {"validate": validate, "format": format, "ignore": ignore, "context": context} # fmt: skip
if self.data is Undefined and "data" not in context:
# No data specified here or in parent: inject empty data
# for easier specification of datum encodings.
copy = self.copy(deep=False)
copy.data = core.InlineData(values=[{}])
return super(Chart, copy).to_dict(
validate=validate, format=format, ignore=ignore, context=context
)
return super().to_dict(
validate=validate, format=format, ignore=ignore, context=context
)
return super(Chart, copy).to_dict(**kwds)
return super().to_dict(**kwds)

def transformed_data(
self, row_limit: int | None = None, exclude: Iterable[str] | None = None
Expand Down

0 comments on commit 419a4e9

Please sign in to comment.