Skip to content

Commit

Permalink
🎨 style(quantity): rename modules (#352)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman <[email protected]>
  • Loading branch information
nstarman authored Dec 23, 2024
1 parent 48519e6 commit edd3952
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/unxt/_src/quantity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/unxt/_src/quantity/register_dispatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .api import ustrip
from .base import AbstractQuantity
from .core import Quantity
from .quantity import Quantity

# -----------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/unxt/_src/quantity/register_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __class_getitem__(
>>> from unxt.quantity import UncheckedQuantity
>>> UncheckedQuantity["length"]
<class 'unxt._src.quantity.fast.UncheckedQuantity'>
<class 'unxt...quantity...UncheckedQuantity'>
"""
return cls
13 changes: 9 additions & 4 deletions src/unxt/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,4 +44,4 @@


# Clean up namespace
del compat, functional, register_dispatches, register_primitives
del register_conversions, register_api, register_dispatches, register_primitives

0 comments on commit edd3952

Please sign in to comment.