Skip to content

Allow for decimal parsing in pydantic model#141

Open
simon-hirsch wants to merge 7 commits into
BerriJ:developfrom
simon-hirsch:pydantic-decimal
Open

Allow for decimal parsing in pydantic model#141
simon-hirsch wants to merge 7 commits into
BerriJ:developfrom
simon-hirsch:pydantic-decimal

Conversation

@simon-hirsch

Copy link
Copy Markdown
Contributor

This MR allows the extract_records function to parse decimals to float for further processing.

Copilot AI review requested due to automatic review settings April 15, 2026 09:14
@simon-hirsch
simon-hirsch changed the base branch from main to develop April 15, 2026 09:14

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 support in extract_records to coerce Pydantic Decimal values into float to simplify downstream numeric processing (e.g., DataFrame usage).

Changes:

  • Introduces recursive Decimal-to-float coercion and a new decimal_to_float flag in extract_records.
  • Adds unit tests covering Decimal coercion (including nested/domain extraction) and the disabled behavior.
  • Updates documentation examples to mention/use the Decimal parsing option.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/entsoe/utils/records.py Adds decimal_to_float parameter and conversion/serialization path for Decimal handling.
tests/test_extract_records.py Adds tests validating Decimal coercion and the opt-out behavior.
docs/examples.md Updates examples and documents Decimal-to-float conversion behavior.

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

Comment thread src/entsoe/utils/records.py
Comment thread src/entsoe/utils/records.py
Comment thread src/entsoe/utils/records.py Outdated
Comment on lines +201 to +206
if decimal_to_float:
# Keep Decimal values typed, coerce them, then normalize to JSON-compatible
# values so the output structure stays aligned with mode="json".
data_dict = [item.model_dump(mode="python") for item in data_list]
data_dict = [_coerce_decimals_to_float(item_dict) for item_dict in data_dict]
data_dict = [_ANY_ADAPTER.dump_python(item_dict, mode="json") for item_dict in data_dict]

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The decimal_to_float=True path switches from model_dump(mode="json") to model_dump(mode="python") plus a generic TypeAdapter(Any) JSON dump. This is only covered by tests using built-in datetime; please add a regression test using one of the library’s real xsdata datatypes (e.g., xsdata.models.datatype.XmlDateTime/XmlDate) to confirm this serialization path remains JSON-compatible for actual API models.

Copilot uses AI. Check for mistakes.
Comment thread docs/examples.md Outdated
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.

2 participants