Skip to content

Conversation

@MatthieuDartiailh
Copy link
Contributor

Updated return type of from_list and from_sequence methods to support numpy arrays.

…[MagnitudeT]]

Updated return type of from_list and from_sequence methods to support numpy arrays.
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 15, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing MatthieuDartiailh:MatthieuDartiailh-Quantity.from_list-typing (8e338e3) with master (9325ea2)

Summary

✅ 448 untouched benchmarks

@andrewgsavage
Copy link
Collaborator

Thanks, this looks fine to merge.
Before I do so, is there a way to test these kind of typing issues to avoid them in the first place?

@MatthieuDartiailh
Copy link
Contributor Author

I did not check what was running in term of type check in the CI. I think mypy should be able to catch this but the rest of teh codebase may not be ready. Another options would be to run mypy on some select files with test assignment.

As a side note, there is still a minor annoyance in the behavior of this function in that it generates a PlainQuantity which is not indexable but since the magnitude is a NDArray, it is indexable and always is. Would it be possible to return a Quantity or another appropriate facet ?

>>> import pint
>>> q1 = pint.Quantity("1V")
>>> q2 = pint.Quantity("1V")
>>> pint.Quantity.from_list([q1, q2])[0]
<Quantity(1.0, 'volt')>

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.

PlainQuantity from_list and from_sequence typing is wrong

2 participants