Skip to content

Add typed panel model for multiple column charts - #553

Closed
palewire wants to merge 1 commit into
mainfrom
sluggo/sluggo-20260726T164425Z-b311466c
Closed

Add typed panel model for multiple column charts#553
palewire wants to merge 1 commit into
mainfrom
sluggo/sluggo-20260726T164425Z-b311466c

Conversation

@palewire

Copy link
Copy Markdown
Collaborator

Summary

  • Add a MultipleColumnPanel Pydantic model for MultipleColumnChart.panels
  • Convert panel dictionaries into typed panel instances while preserving custom/unknown panel options
  • Export the new panel model from datawrapper and datawrapper.charts

Fixes #495.

Tests

  • uv run pytest tests/integration/test_multiple_column_chart.py tests/integration/test_multiple_column_sample_annotations.py tests/unit/test_multiple_column_range_annotation_subclasses.py tests/unit/test_plot_height_mode_enum.py -q
  • uv run ruff check datawrapper/charts/multiple_column.py datawrapper/charts/__init__.py datawrapper/__init__.py tests/integration/test_multiple_column_chart.py
  • uv run ruff format --check datawrapper/charts/multiple_column.py datawrapper/charts/__init__.py datawrapper/__init__.py tests/integration/test_multiple_column_chart.py
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a typed MultipleColumnPanel Pydantic model to represent MultipleColumnChart.panels, ensuring panels are handled as first-class typed objects while still round-tripping unknown/custom panel options.

Changes:

  • Introduces MultipleColumnPanel and converts MultipleColumnChart.panels from list[dict] to list[MultipleColumnPanel] via a field_validator.
  • Updates multiple-column chart serialization to emit panels from typed models (including alias handling and extra fields).
  • Exports MultipleColumnPanel from both datawrapper.charts and top-level datawrapper, and extends integration tests accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/integration/test_multiple_column_chart.py Adds coverage ensuring panels convert to typed models and preserve aliases/extra fields through serialize/deserialize.
datawrapper/charts/multiple_column.py Introduces MultipleColumnPanel, types MultipleColumnChart.panels, converts dict inputs to models, and updates serialization.
datawrapper/charts/init.py Re-exports MultipleColumnPanel from datawrapper.charts.
datawrapper/init.py Re-exports MultipleColumnPanel from top-level datawrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +82 to +84
def serialize_model(self) -> dict[str, Any]:
"""Serialize the panel to Datawrapper's API format."""
return self.model_dump(by_alias=True, exclude_none=True)
@palewire palewire closed this Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Pydantic model for the Panel entries in a MultipleColumnChart

2 participants