GalacticDynamics / unxt

Unitful Quantities in JAX
https://unxt.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11 stars 3 forks source link

Defining a custom unit system breaks unitsystem? #224

Open adrn opened 3 days ago

adrn commented 3 days ago

Something I just noticed when testing unrelated code:

class MyUnitSystem(AbstractUnitSystem):
        length: Annotated[u.Unit, u.get_physical_type("length")]
        time: Annotated[u.Unit, u.get_physical_type("time")]

# raises error:
usys = unitsystem(u.kpc, u.Myr)
        # Return if the unit system is already registered
        if dimensions in UNITSYSTEMS_REGISTRY:
>           return UNITSYSTEMS_REGISTRY[dimensions](*units_)
E           TypeError: AbstractUnitSystem.__init__() takes 1 positional argument but 3 were given
nstarman commented 3 days ago

Hm. This means it's not processing the fields as base dimensions. Can you try u.UnitBase as the annotated type?