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
Make ParticleList
compatible with Quantity
objects with physical type of mass or electrical charge
#1872
Comments
Or - and bear with me here, because this would of course be a bigger rework - we could go the other way around. Instead of going with a "array of structures" layout, we could go with a "structure of arrays" one. Just have |
Interesting! If a |
Closed by #1874. |
Feature description
Right now if we try to create a
ParticleList
using aQuantity
array, we get anInvalidParticleError
:What I'd like to happen is for a
CustomParticle
to be created based on each element of theQuantity
array, i.e.:Motivation
As part of the refactoring of
particle_input
in #1057, we're making it so that aQuantity
of physical type mass or electrical charge will be used to construct aCustomParticle
instance. I discovered in #1871 thatParticleList
works forQuantity
non-arrays but not forQuantity
arrays. The code downstream ofParticleList
will be cleaner and have fewer special cases to handle ifParticleList
can handleQuantity
iterables of these physical types.Implementation strategy
We'll need to make these changes to not only
ParticleList.__init__
, but also theappend
,extend
, andinsert
methods.There's some repeated code in these methods, so it might be worth creating a private function that does the particleification or particlizing.
Additional context
Implementing this would probably be cleaner by allowing mass and charge as positional arguments in either order in
CustomParticle
, kind of like what I attempted in #1364, but maybe having a signature likeCustomParticle(*quantities, mass: Optional[u.kg] = None, charge=Optional[u.C] = None, symbol: Optional[str]=None)
.The text was updated successfully, but these errors were encountered: