Skip to content

[QHC-1609] Add one way numpy scalar serialization - #1208

Open
elygoner wants to merge 3 commits into
mainfrom
qhc-1609-add-one-way-hatch-numpy-scalar-constructor
Open

[QHC-1609] Add one way numpy scalar serialization#1208
elygoner wants to merge 3 commits into
mainfrom
qhc-1609-add-one-way-hatch-numpy-scalar-constructor

Conversation

@elygoner

@elygoner elygoner commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

I have repourposed the compare_platforms i added to compare platform serialization and renamed it to compare_objects since it is general

@linear

linear Bot commented Sep 9, 2026

Copy link
Copy Markdown

QHC-1609

@pullpo-for-slack

Copy link
Copy Markdown

🔗Pullpo.io Slack PR-Channel

@pullpo-for-slack

pullpo-for-slack Bot commented Sep 9, 2026

Copy link
Copy Markdown

AI Analysis

Purpose of the changes:

Enhance YAML serialization and deserialization for NumPy scalars and tuples, improving compatibility with legacy data formats.

Improvements and suggestions

(dropdown):
  • In file src/qililab/yaml.py / legacy_np_scalar_constructor

Issue:
The legacy_np_scalar_constructor does not handle cases where the required keys 'dtype' or 'value' are missing in the mapping.

Suggested solution:
Add error handling to check for the presence of 'dtype' and 'value' in the mapping before accessing them.

Detailed file changes

(dropdown):
  • In file tests/test_yaml.py:

    • Added tests for deserialization of legacy NumPy scalar tags to ensure backward compatibility.
    • Created a utility function dump_to_string for serializing objects to YAML format, improving code reuse.
    • Implemented multiple parameterized tests for various NumPy scalar types and their serialization/deserialization.
  • In file tests/platform/test_platform.py:

    • Replaced the custom compare_platforms function with the more generic compare_objects function, improving code modularity.
  • In file tests/test_utils.py:

    • Introduced a new compare_objects function to recursively compare objects, enhancing test utility functions.
  • In file src/qililab/yaml.py:

    • Added legacy_np_scalar_representer and legacy_np_scalar_constructor to handle legacy NumPy scalar serialization and deserialization.
    • Registered the new representers and constructors with the YAML handler to support legacy formats.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.71%. Comparing base (99f92ff) to head (cd5da35).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1208   +/-   ##
=======================================
  Coverage   98.71%   98.71%           
=======================================
  Files         209      209           
  Lines       11306    11314    +8     
=======================================
+ Hits        11161    11169    +8     
  Misses        145      145           
Flag Coverage Δ
unittests 98.71% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@flavie-lebars flavie-lebars left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Image

Add a bugfix in the changelog please.

@flavie-lebars flavie-lebars left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Image

@sonarqubecloud

Copy link
Copy Markdown

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