Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allowing serialization with numpy types inside of BaseQuantity #63

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

pesap
Copy link
Collaborator

@pesap pesap commented Jan 21, 2025

It turns out that you can create a pint.Quantiy using a numpy type. This PR allows ours custom serialization to cast the numpy types to its python equivalent using .item() from numpy.

@pesap pesap requested a review from daniel-thom January 21, 2025 20:07
@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.11%. Comparing base (7d7fbbf) to head (d6692e6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
+ Coverage   96.06%   96.11%   +0.04%     
==========================================
  Files          36       36              
  Lines        2976     2988      +12     
==========================================
+ Hits         2859     2872      +13     
+ Misses        117      116       -1     

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

@@ -79,6 +79,8 @@ def to_dict(self) -> dict[str, Any]:
val = self.magnitude
if isinstance(self.magnitude, np.ndarray):
val = self.magnitude.tolist()
if isinstance(self.magnitude, np.generic):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this ever conflict with the previous conditional? Should it be elif instead of if?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. I will make it elif

@pesap pesap merged commit 855cf07 into main Jan 21, 2025
6 checks passed
@pesap pesap deleted the ps/numpy branch January 21, 2025 22:48
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.

3 participants