diff --git a/src/unxt/_src/quantity/__init__.py b/src/unxt/_src/quantity/__init__.py index 20a15f83..ce07ff9e 100644 --- a/src/unxt/_src/quantity/__init__.py +++ b/src/unxt/_src/quantity/__init__.py @@ -13,5 +13,5 @@ from .api import is_unit_convertible, uconvert, ustrip from .base import AbstractQuantity from .base_parametric import AbstractParametricQuantity -from .core import Quantity -from .fast import UncheckedQuantity +from .quantity import Quantity +from .unchecked import UncheckedQuantity diff --git a/src/unxt/_src/quantity/core.py b/src/unxt/_src/quantity/quantity.py similarity index 100% rename from src/unxt/_src/quantity/core.py rename to src/unxt/_src/quantity/quantity.py diff --git a/src/unxt/_src/quantity/functional.py b/src/unxt/_src/quantity/register_api.py similarity index 81% rename from src/unxt/_src/quantity/functional.py rename to src/unxt/_src/quantity/register_api.py index 57b67ee3..456a50aa 100644 --- a/src/unxt/_src/quantity/functional.py +++ b/src/unxt/_src/quantity/register_api.py @@ -11,11 +11,49 @@ from .api import ustrip from .base import AbstractQuantity -from unxt._src.dimensions import dimension_of +from unxt._src.dimensions import AbstractDimension, dimension_of from unxt._src.units import unit from unxt._src.units.api import AbstractUnits from unxt._src.units.system import AbstractUnitSystem +# =================================================================== +# Get dimensions + + +@dispatch # type: ignore[misc] +def dimension_of(obj: AbstractQuantity, /) -> AbstractDimension: + """Return the dimension of a quantity. + + Examples + -------- + >>> from unxt import dimension_of, Quantity + >>> q = Quantity(1, "m") + >>> dimension_of(q) + PhysicalType('length') + + """ + return dimension_of(obj.unit) + + +# =================================================================== +# Get units + + +@dispatch # type: ignore[misc] +def unit_of(obj: AbstractQuantity, /) -> AbstractUnits: + """Return the units of an object. + + Examples + -------- + >>> from unxt import unit_of, Quantity + >>> q = Quantity(1, "m") + >>> unit_of(q) + Unit("m") + + """ + return obj.unit + + # =================================================================== # Convert units diff --git a/src/unxt/_src/quantity/compat.py b/src/unxt/_src/quantity/register_conversions.py similarity index 60% rename from src/unxt/_src/quantity/compat.py rename to src/unxt/_src/quantity/register_conversions.py index 6b958484..0b53582c 100644 --- a/src/unxt/_src/quantity/compat.py +++ b/src/unxt/_src/quantity/register_conversions.py @@ -2,55 +2,13 @@ __all__: list[str] = [] -from plum import conversion_method, dispatch +from plum import conversion_method from .api import ustrip from .base import AbstractQuantity -from .core import Quantity -from .fast import UncheckedQuantity -from unxt._src.dimensions import AbstractDimension -from unxt._src.units.api import AbstractUnits - -# =================================================================== -# Get dimensions - - -@dispatch # type: ignore[misc] -def dimension_of(obj: AbstractQuantity, /) -> AbstractDimension: - """Return the dimension of a quantity. - - Examples - -------- - >>> from unxt import dimension_of, Quantity - >>> q = Quantity(1, "m") - >>> dimension_of(q) - PhysicalType('length') - - """ - return dimension_of(obj.unit) - - -# =================================================================== -# Get units - - -@dispatch # type: ignore[misc] -def unit_of(obj: AbstractQuantity, /) -> AbstractUnits: - """Return the units of an object. - - Examples - -------- - >>> from unxt import unit_of, Quantity - >>> q = Quantity(1, "m") - >>> unit_of(q) - Unit("m") - - """ - return obj.unit - - -##################################################################### -# Conversion +from .quantity import Quantity +from .unchecked import UncheckedQuantity +from unxt._src.units.api import unit_of @conversion_method(type_from=AbstractQuantity, type_to=UncheckedQuantity) # type: ignore[misc] diff --git a/src/unxt/_src/quantity/register_dispatches.py b/src/unxt/_src/quantity/register_dispatches.py index 222fcf2e..489247d1 100644 --- a/src/unxt/_src/quantity/register_dispatches.py +++ b/src/unxt/_src/quantity/register_dispatches.py @@ -13,7 +13,7 @@ from .api import ustrip from .base import AbstractQuantity -from .core import Quantity +from .quantity import Quantity # ----------------------------------------------- diff --git a/src/unxt/_src/quantity/register_primitives.py b/src/unxt/_src/quantity/register_primitives.py index aa47c93e..5f25a501 100644 --- a/src/unxt/_src/quantity/register_primitives.py +++ b/src/unxt/_src/quantity/register_primitives.py @@ -28,7 +28,7 @@ from .api import is_unit_convertible, uconvert, ustrip from .base import AbstractQuantity from .base_parametric import AbstractParametricQuantity -from .core import Quantity +from .quantity import Quantity from unxt._src.units import unit, unit_of from unxt._src.utils import promote_dtypes_if_needed diff --git a/src/unxt/_src/quantity/fast.py b/src/unxt/_src/quantity/unchecked.py similarity index 95% rename from src/unxt/_src/quantity/fast.py rename to src/unxt/_src/quantity/unchecked.py index b2f0cab3..19cb653c 100644 --- a/src/unxt/_src/quantity/fast.py +++ b/src/unxt/_src/quantity/unchecked.py @@ -35,7 +35,7 @@ def __class_getitem__( >>> from unxt.quantity import UncheckedQuantity >>> UncheckedQuantity["length"] - + """ return cls diff --git a/src/unxt/quantity.py b/src/unxt/quantity.py index e6b53f3c..25c44416 100644 --- a/src/unxt/quantity.py +++ b/src/unxt/quantity.py @@ -15,12 +15,17 @@ from ._src.quantity.api import is_unit_convertible, uconvert, ustrip from ._src.quantity.base import AbstractQuantity from ._src.quantity.base_parametric import AbstractParametricQuantity -from ._src.quantity.core import Quantity -from ._src.quantity.fast import UncheckedQuantity +from ._src.quantity.quantity import Quantity +from ._src.quantity.unchecked import UncheckedQuantity # isort: split # Register dispatches and conversions -from ._src.quantity import compat, functional, register_dispatches, register_primitives +from ._src.quantity import ( + register_api, + register_conversions, + register_dispatches, + register_primitives, +) __all__: list[str] = [ # Core @@ -39,4 +44,4 @@ # Clean up namespace -del compat, functional, register_dispatches, register_primitives +del register_conversions, register_api, register_dispatches, register_primitives