unitx 0.17.2__tar.gz → 0.17.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unitx-0.17.2 → unitx-0.17.3}/.github/consumers/arrays.py +43 -6
- {unitx-0.17.2 → unitx-0.17.3}/.github/consumers/scalars.py +12 -0
- {unitx-0.17.2 → unitx-0.17.3}/CHANGELOG.md +27 -0
- {unitx-0.17.2 → unitx-0.17.3}/PKG-INFO +1 -1
- {unitx-0.17.2 → unitx-0.17.3}/docs/architecture.md +6 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/calculus.md +39 -4
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy.md +6 -5
- {unitx-0.17.2 → unitx-0.17.3}/docs/typing.md +39 -11
- {unitx-0.17.2 → unitx-0.17.3}/docs/units.md +17 -0
- {unitx-0.17.2 → unitx-0.17.3}/pyproject.toml +1 -1
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/points.py +4 -4
- unitx-0.17.3/src/unitx/_numerics/methods.py +31 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy.py +36 -17
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy_typing.py +16 -2
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/affinequantity.py +21 -38
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/exceptions.py +11 -1
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/logquantity.py +21 -38
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/quantity.py +14 -42
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/quantity.pyi +319 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/unitregistry.py +2 -2
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_array_methods.py +10 -0
- unitx-0.17.3/tests/numpy/test_dtype_contracts.py +74 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_scientific.py +1 -1
- unitx-0.17.3/tests/numpy/test_point_calculus.py +110 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_array_methods.py +2 -2
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_numpy.py +19 -13
- unitx-0.17.3/tests/numpy_typing/check_precision.py +48 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_representation.py +4 -5
- unitx-0.17.3/tests/test_exceptions.py +36 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_typing.py +1 -1
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_impedance_example.py +3 -3
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_quantity.py +2 -2
- {unitx-0.17.2 → unitx-0.17.3}/.github/consumers/plots.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.github/consumers/pyrightconfig.json +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.github/consumers/scipy_support.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.github/workflows/ci.yml +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.github/workflows/pages.yml +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.github/workflows/release.yml +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.gitignore +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/.readthedocs.yaml +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/CONTRIBUTING.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/LICENSE +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/benchmarks/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/benchmarks/numpy_writes.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/benchmarks/scalars.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/conftest.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/affine.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/catalogues/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/catalogues/cgs.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/catalogues/imperial.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/catalogues/si.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/custom-units.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/display.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/images/blackbody.svg +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/javascripts/mermaid.mjs +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/logarithmic.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/matplotlib.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/migration.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/compatibility.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/contractions.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/creation.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/fft.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/histograms.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/indexing.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/linalg.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/methods.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/selection.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/statistics.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/numpy/writes.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/representation.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/requirements.txt +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/scalars.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/scipy.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/serialization.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/statistics.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/docs/stdlib.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/arrhenius_fit.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/blackbody.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/damped_oscillator.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/gaussian_wavepacket.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/impedance.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/impedance.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/optical_attenuation.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/pendulum_uncertainty.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/examples/smith_chart.ipynb +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/mkdocs.yml +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/pyrightconfig.json +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_constnamespace.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/affine.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/definition.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/logarithmic.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/logarithms.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_coordinates/resolve.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_electromagnetism/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_electromagnetism/coefficients.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_electromagnetism/conversion.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_formatting/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_formatting/render.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_formatting/unicode.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_immutable.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/conversion.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy_creation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy_histograms.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy_misc.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/numpy_writes.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_numerics/scaling.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_operands.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_registry/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_registry/builtin_units.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_registry/prefixes.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_registry/reconstruction.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/_representation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/affineunit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/cgs/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/cgs/units.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/dimension.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/factor.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/imperial/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/imperial/units.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/logunit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/math.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/matplotlib.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/monomial.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/py.typed +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/scipy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/serialization.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/si/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/si/bases.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/si/constants.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/si/units.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/singleunit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/time.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/unit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/unitcatalog.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/unitdefinition.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/src/unitx/unitparser.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/README.md +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/_notebooks.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/algebra/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/algebra/test_dimension.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/algebra/test_factor.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/algebra/test_monomial.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/algebra/test_numeric.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/test_cgs.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/test_cgs_systems.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/test_imperial.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/test_si.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/catalogues/test_unicode_units.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/display/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/display/test_display.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/display/test_siunitx_display.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/display/test_unicode.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/conftest.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_cgs_numpy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_math_numpy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_affine.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_array_manipulation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_compatibility.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_contractions.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_covariance.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_creation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_differentiation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_factorizations.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_fft.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_histograms.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_indexing.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_integration.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_interpolation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_joining.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_linalg.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_math.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_multi_outputs.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_mutation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_nan_reductions.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_nan_statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_norm.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_ordering.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_outputs.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_products.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_selection.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_shapes.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_ufunc_methods.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_weighted_statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_workflows.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy/test_numpy_write_functions.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_asarray.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_cgs.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_components.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_indexing.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_logarithmic.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_math.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/numpy_typing/check_scipy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_affine.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_affinequantity.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_decibel_call.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_float_decimal.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_linear_boundaries.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_logarithmic_model.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_quantity.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_quantity_astype.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_representation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/quantities/test_scalar_protocols.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/stdlib/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/stdlib/test_math.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/stdlib/test_scipy.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/stdlib/test_statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/stdlib/test_time.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_examples.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_immutable.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_impedance_example.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_import.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_matplotlib.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_serialization.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/test_warnings.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_affine.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_cgs.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_float.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_imperial.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_logarithmic.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_math_time.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_registry.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_representation.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_serialization.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_si.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/typing/check_statistics.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/__init__.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_builtin_definitions.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_catalog_collection.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_definition_scope.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_registry.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_registry_scope.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_singleunit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_unit.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_unit_definition.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_unitparser.py +0 -0
- {unitx-0.17.2 → unitx-0.17.3}/tests/units/test_unitregistry.py +0 -0
|
@@ -9,7 +9,7 @@ from unitx import AffineQuantity, LogQuantity, LogUnit, Quantity, Unit
|
|
|
9
9
|
from unitx._numerics import Array
|
|
10
10
|
from unitx._numerics.numpy_typing import NumpyValue
|
|
11
11
|
from unitx.cgs import emu, esu, gaussian, hl
|
|
12
|
-
from unitx.exceptions import DimensionError
|
|
12
|
+
from unitx.exceptions import DimensionError, ImplicitConversionError, UnitOperationError
|
|
13
13
|
from unitx.si import si
|
|
14
14
|
|
|
15
15
|
type ArrayQuantity = Quantity[Array] | AffineQuantity[Array] | LogQuantity[Array]
|
|
@@ -29,13 +29,13 @@ def check_components(signal: Quantity[NDArray[np.complex128]]) -> None:
|
|
|
29
29
|
|
|
30
30
|
def check_arrays(values: NDArray[np.float64]) -> None:
|
|
31
31
|
ratio = Quantity(values, si.percent)
|
|
32
|
-
assert_type(ratio.n,
|
|
32
|
+
assert_type(ratio.n, NDArray[np.float64] | np.float64)
|
|
33
33
|
np.testing.assert_allclose(ratio.n, values / 100)
|
|
34
34
|
assert_type(ratio.as_pair(), tuple[NDArray[np.float64], Unit])
|
|
35
35
|
assert ratio.as_pair()[0] is values
|
|
36
|
-
assert_type(ratio.to_base(), Quantity[
|
|
37
|
-
assert_type(ratio.simplify(), Quantity[
|
|
38
|
-
assert_type(Quantity(values, si.m).compact(), Quantity[
|
|
36
|
+
assert_type(ratio.to_base(), Quantity[NDArray[np.float64] | np.float64])
|
|
37
|
+
assert_type(ratio.simplify(), Quantity[NDArray[np.float64] | np.float64])
|
|
38
|
+
assert_type(Quantity(values, si.m).compact(), Quantity[NDArray[np.float64] | np.float64])
|
|
39
39
|
assert Quantity(values, si.cm * si.m).simplify().unit == si.m**2
|
|
40
40
|
signal = Quantity(np.asarray([3 + 4j], dtype=np.complex128), si.V)
|
|
41
41
|
check_components(signal)
|
|
@@ -555,7 +555,7 @@ def check_array_methods(target: NDArray[np.float64]) -> None:
|
|
|
555
555
|
assert_type(columns, Quantity[NDArray[np.float32]])
|
|
556
556
|
assert_type(columns.ravel(), Quantity[NDArray[np.float32]])
|
|
557
557
|
assert_type(columns.copy(), Quantity[NDArray[np.float32]])
|
|
558
|
-
assert_type(columns.mean(axis=0), Quantity[
|
|
558
|
+
assert_type(columns.mean(axis=0), Quantity[NDArray[np.float32] | np.float32])
|
|
559
559
|
assert np.shares_memory(columns.value, values)
|
|
560
560
|
assert not np.shares_memory(columns.copy().value, values)
|
|
561
561
|
out = Quantity(target, si.cm)
|
|
@@ -578,3 +578,40 @@ def check_array_methods(target: NDArray[np.float64]) -> None:
|
|
|
578
578
|
|
|
579
579
|
|
|
580
580
|
check_array_methods(np.zeros(2, dtype=np.float64))
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def check_calculus_types(values: NDArray[np.float64]) -> None:
|
|
584
|
+
coordinate = Quantity(values, si.s)
|
|
585
|
+
signal = 2 * Quantity(values, si.A)
|
|
586
|
+
assert_type(coordinate.to(si.ms), Quantity[NDArray[np.float64] | np.float64])
|
|
587
|
+
assert_type(signal * coordinate, Quantity[NDArray[np.float64] | np.float64])
|
|
588
|
+
weights = cast(Quantity[Array], np.gradient(coordinate, axis=0))
|
|
589
|
+
weights[[0, -1]] /= 2
|
|
590
|
+
integral = cast(Quantity[Array], np.trapezoid(signal, coordinate))
|
|
591
|
+
assert np.sum(signal * weights).isclose(integral)
|
|
592
|
+
points = AffineQuantity(values, si.degC)
|
|
593
|
+
increments = cast(Quantity[Array], np.diff(points))
|
|
594
|
+
assert increments.unit == si.degC.delta_unit
|
|
595
|
+
assert np.diff(points, n=0) is points
|
|
596
|
+
rate = cast(Quantity[Array], np.gradient(points, coordinate, axis=0))
|
|
597
|
+
np.testing.assert_allclose(rate.value, 1)
|
|
598
|
+
levels = LogQuantity(values, si.dBm)
|
|
599
|
+
differences = cast(Quantity[Array], np.diff(levels))
|
|
600
|
+
assert differences.unit == si.dBm.delta_unit
|
|
601
|
+
try:
|
|
602
|
+
np.asarray(coordinate)
|
|
603
|
+
except ImplicitConversionError as error:
|
|
604
|
+
assert isinstance(error, TypeError)
|
|
605
|
+
else:
|
|
606
|
+
error_message = 'Array coercion must preserve the explicit numerical boundary.'
|
|
607
|
+
raise AssertionError(error_message)
|
|
608
|
+
try:
|
|
609
|
+
np.add(points, points)
|
|
610
|
+
except UnitOperationError as error:
|
|
611
|
+
assert isinstance(error, TypeError)
|
|
612
|
+
else:
|
|
613
|
+
error_message = 'Adding two points must fail.'
|
|
614
|
+
raise AssertionError(error_message)
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
check_calculus_types(np.array([0.0, 1, 3, 6]))
|
|
@@ -26,6 +26,7 @@ from unitx import (
|
|
|
26
26
|
time,
|
|
27
27
|
)
|
|
28
28
|
from unitx.cgs import cgs, emu, esu, gaussian, hl
|
|
29
|
+
from unitx.exceptions import ImplicitConversionError, UnitOperationError, UnitxError
|
|
29
30
|
from unitx.factor import Factor
|
|
30
31
|
from unitx.imperial import imperial
|
|
31
32
|
from unitx.quantity import quantity as decimal_quantity
|
|
@@ -185,3 +186,14 @@ assert 'matplotlib' not in sys.modules
|
|
|
185
186
|
# The sibling stub must retain the module-level Decimal factory.
|
|
186
187
|
assert_type(decimal_quantity(1.25, si.m), Quantity[Decimal])
|
|
187
188
|
assert decimal_quantity(1.25, si.m).value == Decimal('1.25')
|
|
189
|
+
|
|
190
|
+
assert issubclass(UnitOperationError, TypeError)
|
|
191
|
+
assert issubclass(UnitOperationError, UnitxError)
|
|
192
|
+
assert issubclass(ImplicitConversionError, UnitOperationError)
|
|
193
|
+
try:
|
|
194
|
+
_ = (20 @ si.degC) * 2
|
|
195
|
+
except UnitOperationError as error:
|
|
196
|
+
assert isinstance(error, TypeError)
|
|
197
|
+
else:
|
|
198
|
+
error_message = 'Multiplying a coordinate point must fail.'
|
|
199
|
+
raise AssertionError(error_message)
|
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.17.3] - 2026-10-27
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Support `diff` and `gradient` on affine/logarithmic point arrays, returning
|
|
8
|
+
differences and using coordinate difference units for derivatives. Align
|
|
9
|
+
point boundaries explicitly; retain the original object for `diff(n=0)`.
|
|
10
|
+
- Document reusable trapezoidal weights using `np.gradient` and an endpoint
|
|
11
|
+
correction.
|
|
12
|
+
- Add `UnitOperationError` for point/difference semantic violations and its
|
|
13
|
+
`ImplicitConversionError` subclass for silent array unit removal. Both remain
|
|
14
|
+
catchable as TypeError and UnitxError; native numerical errors stay native.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Delegate direct array methods through a private lazy decorator, retaining
|
|
19
|
+
explicit signatures, method defaults and the existing NumPy unit/output rules.
|
|
20
|
+
- Retain known floating/complex NumPy dtypes in linear conversions, supported
|
|
21
|
+
arithmetic and default sum/mean results, including possible NumPy scalars.
|
|
22
|
+
Preserve numeric dtypes in indexing/iteration; narrow exact Fraction
|
|
23
|
+
arithmetic and complex scalar result domains.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Update the generator annotation on registry definition scopes to avoid the
|
|
28
|
+
deprecated Iterator overload of `contextmanager` in current type stubs.
|
|
29
|
+
|
|
3
30
|
## [0.17.2] - 2026-10-27
|
|
4
31
|
|
|
5
32
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: unitx
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.3
|
|
4
4
|
Summary: Physical units, quantities, and unit conversion with exact unit algebra, type hints, and NumPy integration.
|
|
5
5
|
Project-URL: Homepage, https://github.com/DaitTHU/unitx
|
|
6
6
|
Project-URL: Documentation, https://daitthu.github.io/unitx/
|
|
@@ -165,6 +165,12 @@ enumerate their own reference/difference dependencies. Display, NumPy and
|
|
|
165
165
|
serialization remain explicit integration boundaries. Numeric caches, parser
|
|
166
166
|
state and reconstruction indexes remain separate from mathematical identity.
|
|
167
167
|
|
|
168
|
+
Direct array methods declare their public signatures explicitly. A private
|
|
169
|
+
decorator in `_numerics/methods.py` binds their defaults and lazily delegates to
|
|
170
|
+
the same NumPy dispatch used by function calls. It adds no dynamic method lookup
|
|
171
|
+
or separate unit rules; coordinate and linear result construction stays in the
|
|
172
|
+
existing handlers. Reshape keeps its explicit positional-shape normalization.
|
|
173
|
+
|
|
168
174
|
The point marker's type parameter describes the result of adding a difference,
|
|
169
175
|
not the original magnitude type. This prevents the open scalar protocol from
|
|
170
176
|
claiming point operands and preserves concrete result types without naming the
|
|
@@ -69,13 +69,18 @@ No coordinate sorting, interpolation, dtype option, or output buffer is added.
|
|
|
69
69
|
|
|
70
70
|
## Differences and gradients
|
|
71
71
|
|
|
72
|
-
`np.diff(q, n=1, axis=-1)` computes differences in q's stored coordinates
|
|
73
|
-
|
|
72
|
+
`np.diff(q, n=1, axis=-1)` computes differences in q's stored coordinates.
|
|
73
|
+
Linear quantities retain their unit; AffineQuantity and LogQuantity points
|
|
74
|
+
return ordinary Quantities in their complete difference unit for every positive
|
|
75
|
+
order n. Logarithmic differences describe changes in readings, without an
|
|
76
|
+
implicit conversion to physical power or amplitude. `prepend` and `append` may be numeric
|
|
74
77
|
scalars/arrays or Quantities; their dimensions must match the input, and their
|
|
75
78
|
values convert to the input unit before differencing. Bare boundaries are
|
|
76
79
|
dimensionless, including bare zero. A bare input with a Quantity boundary is
|
|
77
80
|
also dimensionless. Scaled dimensionless boundaries therefore normalize to the
|
|
78
81
|
input's coordinates. Explicit list inputs/boundaries remain unsupported.
|
|
82
|
+
For points, boundaries must be compatible points and convert to the input
|
|
83
|
+
coordinate first; a difference or bare zero cannot stand in for a point.
|
|
79
84
|
|
|
80
85
|
With `n=0`, diff returns its input object unchanged and ignores axis and
|
|
81
86
|
boundaries. Other orders follow [NumPy diff](https://numpy.org/doc/stable/reference/generated/numpy.diff.html)
|
|
@@ -83,12 +88,15 @@ for shapes, scalar-boundary expansion, dtype promotion, unsigned wraparound,
|
|
|
83
88
|
and empty results. A difference is not a derivative: its unit is not divided
|
|
84
89
|
by a coordinate unit or raised to n.
|
|
85
90
|
|
|
86
|
-
`np.gradient(f, *spacing, axis=None, edge_order=1)` accepts numeric
|
|
87
|
-
|
|
91
|
+
`np.gradient(f, *spacing, axis=None, edge_order=1)` accepts numeric values,
|
|
92
|
+
Quantities and coordinate points. Each spacing is a scalar difference step or one-dimensional coordinate
|
|
88
93
|
array; bare inputs and spacings are dimensionless. A single scalar step applies
|
|
89
94
|
to every selected axis. Otherwise supply one spacing per selected axis, in
|
|
90
95
|
the order given by axis. Each component has unit `f.unit / spacing.unit`,
|
|
91
96
|
including exact Unit factors. No spacing means dimensionless unit steps.
|
|
97
|
+
For point-valued f, use its difference unit in the numerator. A point coordinate
|
|
98
|
+
array contributes its difference unit in the denominator; a scalar point is
|
|
99
|
+
not a step. Changing a coordinate origin does not change the derivative.
|
|
92
100
|
The kernels use stored numerical coordinates; no implicit SI conversion is
|
|
93
101
|
needed because each result retains the corresponding unit ratio.
|
|
94
102
|
|
|
@@ -112,4 +120,31 @@ np.testing.assert_allclose(velocity.value, 2)
|
|
|
112
120
|
assert np.trapezoid(velocity, time).isclose(distance[-1] - distance[0])
|
|
113
121
|
```
|
|
114
122
|
|
|
123
|
+
## Reusable trapezoidal weights
|
|
124
|
+
|
|
125
|
+
For repeated weighted sums or contractions on a real one-dimensional grid of
|
|
126
|
+
at least two samples, compute weights with gradient and halve the endpoints:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
time = Quantity(np.array([0.0, 1, 3, 6]), 's')
|
|
130
|
+
current = Quantity(np.array([0.0, 2, 6, 12]), 'A')
|
|
131
|
+
weights = np.gradient(time, axis=0)
|
|
132
|
+
weights[[0, -1]] /= 2
|
|
133
|
+
np.testing.assert_allclose(weights.value, [0.5, 1.5, 2.5, 1.5])
|
|
134
|
+
assert np.sum(current * weights).isclose(np.trapezoid(current, time))
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
With no spacing argument and the default `edge_order=1`, interior gradient
|
|
138
|
+
entries are `(x[i+1] - x[i-1]) / 2`, half the sum of adjacent intervals.
|
|
139
|
+
Endpoints are full one-sided intervals, so their halving is essential.
|
|
140
|
+
This is mathematically equivalent to trapezoidal weights; floating-point
|
|
141
|
+
rounding order can differ from interval-by-interval integration.
|
|
142
|
+
Decreasing and nonmonotonic coordinates retain their interval signs.
|
|
143
|
+
Gradient needs at least two samples; handle empty/singleton grids locally
|
|
144
|
+
only when the calculation requires them. Point coordinates return difference
|
|
145
|
+
weights; logarithmic readings are not implicitly mapped to physical values.
|
|
146
|
+
|
|
147
|
+
For a single integral, use `np.trapezoid`, following the linear integration
|
|
148
|
+
contract above. NumPy function stubs retain the [documented typing limits](../typing.md#numpy-magnitude-types).
|
|
149
|
+
|
|
115
150
|
[NumPy overview and support matrix](../numpy.md) · [Documentation index](../README.md)
|
|
@@ -33,7 +33,8 @@ differences, and point sums/products are rejected.
|
|
|
33
33
|
## Values, storage, and precision
|
|
34
34
|
|
|
35
35
|
`.value`, `.value_in(unit)`, and `.to(unit).value` are explicit numerical exits.
|
|
36
|
-
`np.asarray(q)` and `np.array(q)` raise
|
|
36
|
+
`np.asarray(q)` and `np.array(q)` raise `ImplicitConversionError` (a TypeError)
|
|
37
|
+
even for dimensionless q;
|
|
37
38
|
use `np.asarray(q.value_in(target_unit))`.
|
|
38
39
|
|
|
39
40
|
Construction, unit-only multiplication/division, and an identity conversion
|
|
@@ -212,8 +213,8 @@ functions, including exp/log. Python scalar arithmetic follows the separate [sca
|
|
|
212
213
|
| argmin/nanargmin, argmax/nanargmax | Bare indices | axis, keepdims, out |
|
|
213
214
|
| interp | Align x to xp's unit; retain fp's unit | finite strictly increasing 1-D xp; scalar left/right, period=None; no out |
|
|
214
215
|
| trapezoid | Multiply ordinate and coordinate units | x, scalar dx, axis; no out |
|
|
215
|
-
| diff | Preserve
|
|
216
|
-
| gradient | Divide input unit by each coordinate unit | scalar spacings or coordinate arrays, axis, edge_order; no out |
|
|
216
|
+
| diff | Preserve linear unit; point inputs return differences for n > 0 | n, axis, compatible point/value prepend and append; no out |
|
|
217
|
+
| gradient | Divide input difference unit by each coordinate difference unit | scalar difference spacings or coordinate arrays, axis, edge_order; no out |
|
|
217
218
|
| isclose, allclose | Bare mask / Python bool | rtol, atol, equal_nan |
|
|
218
219
|
|
|
219
220
|
Supply the first magnitude argument positionally; concatenate/stack take a
|
|
@@ -235,8 +236,8 @@ behavior for augmented arithmetic.
|
|
|
235
236
|
`squeeze`, `expand_dims`, `moveaxis`, `swapaxes`, `rollaxis`, and `ravel`
|
|
236
237
|
operate on magnitudes without conversion. Like reshape and transpose, they
|
|
237
238
|
retain the complete unit or point coordinate and return the same family:
|
|
238
|
-
Quantity, AffineQuantity, or LogQuantity.
|
|
239
|
-
|
|
239
|
+
Quantity, AffineQuantity, or LogQuantity. Ravel also has a direct method;
|
|
240
|
+
these functions have no `out` option.
|
|
240
241
|
|
|
241
242
|
Axis rules and errors follow NumPy, including negative and tuple axes where
|
|
242
243
|
supported. Squeezing an ndarray whose axes all have length one produces a
|
|
@@ -118,19 +118,47 @@ domain; they are not a template for preserving every array or coordinate overloa
|
|
|
118
118
|
The `unitx._numerics` package defines `Scalar`, `Array`, and `Magnitude = Array | Scalar`
|
|
119
119
|
without importing NumPy. Array is an input capability protocol, not a guarantee
|
|
120
120
|
of other backend support. Construction and unit-only operators preserve
|
|
121
|
-
Quantity[T], as does `.T`.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
Quantity[T], as does `.T`. For a known NumPy floating or complex dtype S,
|
|
122
|
+
linear conversion, `n`, unary signs, same-dtype array arithmetic, multiplication
|
|
123
|
+
and division by Python real scalars, and real Python scalar powers retain
|
|
124
|
+
`Quantity[NDArray[S] | S]`. Sum and mean retain this dtype when dtype/out are
|
|
125
|
+
omitted. Indexing and iteration retain known numeric dtypes, including integers.
|
|
126
|
+
Shape/copy methods retain a known ndarray dtype without retaining its shape.
|
|
127
|
+
Other numerical paths use `Quantity[NDArray[Any] | numpy.number[Any]]`, including
|
|
128
|
+
mixed NumPy dtypes, integer conversion and array/scalar aligned addition.
|
|
129
|
+
For example, scaling a Python scalar before addition can introduce a strong
|
|
130
|
+
float64 NumPy scalar and promote a float32 array. General scalar annotations
|
|
131
|
+
can also hide NumPy scalar subclasses; concrete dtype inference assumes inputs
|
|
132
|
+
describe their actual numerical domains.
|
|
133
|
+
|
|
134
|
+
`.value` exposes native NumPy methods; `.flatten()` returns an ndarray.
|
|
135
|
+
Reduction `out` retains the concrete destination type. Point shape/copy/mean
|
|
136
|
+
retain their coordinate family, while std returns a Quantity difference. The
|
|
137
|
+
NumPy diff and gradient functions also return differences. Point sums remain
|
|
138
|
+
undefined. `.dtype` exposes
|
|
139
|
+
a NumPy dtype. Possible zero-dimensional-array to NumPy-scalar results remain
|
|
140
|
+
in the result union.
|
|
132
141
|
Boolean comparisons and isclose retain the NumPy-independent Array protocol.
|
|
133
142
|
|
|
143
|
+
```python
|
|
144
|
+
import numpy as np
|
|
145
|
+
from numpy.typing import NDArray
|
|
146
|
+
from typing import assert_type
|
|
147
|
+
from unitx import Quantity
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def travel(time: Quantity[NDArray[np.float64]]) -> None:
|
|
151
|
+
distance = Quantity(2.5, 'm/s') * time
|
|
152
|
+
assert_type(distance, Quantity[NDArray[np.float64] | np.float64])
|
|
153
|
+
assert_type(distance.to('cm'), Quantity[NDArray[np.float64] | np.float64])
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Fraction multiplication/division with integers or Fractions retain Fraction.
|
|
157
|
+
Complex scalar arithmetic/conversion uses concrete complex or Number domains
|
|
158
|
+
instead of the open Scalar fallback. A Python complex annotation can also hide
|
|
159
|
+
an int, whose conversion may produce a Fraction; its conversion therefore keeps
|
|
160
|
+
the Number union. Float conversion keeps the Real union for the same reason.
|
|
161
|
+
|
|
134
162
|
`Scalar` is nonrecursive: its arithmetic methods return object at the protocol
|
|
135
163
|
boundary, while equality still returns bool. Concrete scalar and array result
|
|
136
164
|
types are described by Quantity's public overloads. Custom scalar magnitudes
|
|
@@ -141,6 +141,23 @@ returns `False`.
|
|
|
141
141
|
For repeated conversions, reuse a target `Unit` object to avoid parsing the
|
|
142
142
|
expression on every call.
|
|
143
143
|
|
|
144
|
+
### Catching errors
|
|
145
|
+
|
|
146
|
+
Import domain exceptions from `unitx.exceptions`:
|
|
147
|
+
|
|
148
|
+
| Exception | Catch when |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `DimensionError` | Units, dimensions or coordinate conventions are incompatible |
|
|
151
|
+
| `UnitOperationError` | An operation violates point/difference semantics, such as adding two points |
|
|
152
|
+
| `ImplicitConversionError` | Array conversion would silently discard units or coordinates |
|
|
153
|
+
| `UnitSymbolError`, `UnitSyntaxError`, `UnitRegistryError` | Looking up, parsing or registering units fails |
|
|
154
|
+
|
|
155
|
+
`ImplicitConversionError` is a subclass of `UnitOperationError`; both also
|
|
156
|
+
inherit TypeError, preserving existing catches. `UnitxError` catches unitx's
|
|
157
|
+
domain exceptions together. Native numerical, shape, dtype and argument errors
|
|
158
|
+
remain their original Python/NumPy exceptions; an unsupported NumPy dispatch
|
|
159
|
+
may also raise TypeError. They are not all reclassified as `UnitxError`.
|
|
160
|
+
|
|
144
161
|
### Dimensionless numerical values
|
|
145
162
|
|
|
146
163
|
`q.n` is a read-only shorthand for `q.value_in(si.one)`. It checks complete
|
|
@@ -4,7 +4,7 @@ build-backend = 'hatchling.build'
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = 'unitx'
|
|
7
|
-
version = '0.17.
|
|
7
|
+
version = '0.17.3'
|
|
8
8
|
description = 'Physical units, quantities, and unit conversion with exact unit algebra, type hints, and NumPy integration.'
|
|
9
9
|
readme = 'README.md'
|
|
10
10
|
requires-python = '>=3.12'
|
|
@@ -12,7 +12,7 @@ from .._numerics import is_numpy_object
|
|
|
12
12
|
from .._numerics.scaling import _finite
|
|
13
13
|
from .._numerics.scaling import affine_value as _affine
|
|
14
14
|
from .._operands import _Point
|
|
15
|
-
from ..exceptions import DimensionError
|
|
15
|
+
from ..exceptions import DimensionError, UnitOperationError
|
|
16
16
|
from ..quantity import Quantity
|
|
17
17
|
from ..unit import Unit
|
|
18
18
|
from .resolve import _Coordinate
|
|
@@ -28,11 +28,11 @@ def _addition_parts(
|
|
|
28
28
|
b, a, unit = _addition_parts(right, left, subtract=False)
|
|
29
29
|
return a, b, unit
|
|
30
30
|
error_message = 'A difference cannot subtract an affine point.'
|
|
31
|
-
raise
|
|
31
|
+
raise UnitOperationError(error_message)
|
|
32
32
|
if isinstance(right, _Point):
|
|
33
33
|
if not subtract:
|
|
34
34
|
error_message = 'Two affine points cannot be added.'
|
|
35
|
-
raise
|
|
35
|
+
raise UnitOperationError(error_message)
|
|
36
36
|
if not left.unit._compatible_with(right.unit):
|
|
37
37
|
error_message = 'Point subtraction requires the same coordinate convention.'
|
|
38
38
|
raise DimensionError(error_message)
|
|
@@ -44,7 +44,7 @@ def _addition_parts(
|
|
|
44
44
|
return left.value, convert(raw, right.unit, left.unit), left.unit.delta_unit
|
|
45
45
|
if not isinstance(right, Quantity):
|
|
46
46
|
error_message = 'Point arithmetic requires an explicit Quantity difference.'
|
|
47
|
-
raise
|
|
47
|
+
raise UnitOperationError(error_message)
|
|
48
48
|
delta = convert(right.value, right.unit, left.unit.delta_unit)
|
|
49
49
|
if isinstance(left.value, Decimal) and isinstance(delta, (int, Fraction)):
|
|
50
50
|
delta = _affine(Decimal(0), 1, delta)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Lazy delegation of explicitly declared methods to the NumPy adapters."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from inspect import signature
|
|
6
|
+
from typing import Any, cast
|
|
7
|
+
|
|
8
|
+
from .numpy_typing import _UNSET
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def numpy_method[**P, R](method: Callable[P, R]) -> Callable[P, R]:
|
|
12
|
+
"""Use the declaration's signature/defaults and the existing NumPy dispatch.
|
|
13
|
+
|
|
14
|
+
Keep this private: each public method still declares its own typed contract.
|
|
15
|
+
NumPy is imported only when a method is called on a NumPy magnitude.
|
|
16
|
+
"""
|
|
17
|
+
parameters = signature(method)
|
|
18
|
+
|
|
19
|
+
@wraps(method)
|
|
20
|
+
def call(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
21
|
+
bound = parameters.bind(*args, **kwargs)
|
|
22
|
+
bound.apply_defaults()
|
|
23
|
+
quantity: Any = bound.arguments.pop('self')
|
|
24
|
+
quantity._array_value()
|
|
25
|
+
from . import numpy
|
|
26
|
+
|
|
27
|
+
options = {name: value for name, value in bound.arguments.items() if value is not _UNSET}
|
|
28
|
+
function = getattr(numpy.np, method.__name__)
|
|
29
|
+
return cast(R, numpy.dispatch_function(function, (), (quantity,), options))
|
|
30
|
+
|
|
31
|
+
return call
|
|
@@ -23,7 +23,7 @@ from .._coordinates.resolve import convert_point as convert
|
|
|
23
23
|
from .._operands import _Point, linear_unit
|
|
24
24
|
from ..affinequantity import AffineQuantity
|
|
25
25
|
from ..dimension import DIMENSIONLESS
|
|
26
|
-
from ..exceptions import _WARNING_SKIP_PREFIXES, DimensionError
|
|
26
|
+
from ..exceptions import _WARNING_SKIP_PREFIXES, DimensionError, UnitOperationError
|
|
27
27
|
from ..factor import Factor, one
|
|
28
28
|
from ..logquantity import LogQuantity
|
|
29
29
|
from ..quantity import Quantity
|
|
@@ -107,7 +107,8 @@ def _operand_parts(value: Any) -> tuple[Any, Unit | _Coordinate]:
|
|
|
107
107
|
def _linear_parts(value: Any) -> tuple[Any, Unit]:
|
|
108
108
|
raw, unit = _operand_parts(value)
|
|
109
109
|
if not isinstance(unit, Unit):
|
|
110
|
-
|
|
110
|
+
error_message = 'This operation requires linear quantities or differences.'
|
|
111
|
+
raise UnitOperationError(error_message)
|
|
111
112
|
return raw, unit
|
|
112
113
|
|
|
113
114
|
|
|
@@ -115,7 +116,8 @@ def _align_operands(left: Any, right: Any) -> tuple[Any, Any, Unit]:
|
|
|
115
116
|
a, u = _linear_parts(left)
|
|
116
117
|
b, v = _linear_parts(right)
|
|
117
118
|
if isinstance(u, _Coordinate) or isinstance(v, _Coordinate):
|
|
118
|
-
|
|
119
|
+
error_message = 'Use point/difference arithmetic for affine coordinates.'
|
|
120
|
+
raise UnitOperationError(error_message)
|
|
119
121
|
if not compatible(u, v):
|
|
120
122
|
raise DimensionError('Cannot operate on incompatible dimensions or logarithmic degrees.')
|
|
121
123
|
# Addition retains the first Quantity's unit, even with a bare left input.
|
|
@@ -135,7 +137,7 @@ def _selection_parts(left: Any, right: Any) -> tuple[Any, Any, Unit | _Coordinat
|
|
|
135
137
|
if isinstance(left, _Point) or isinstance(right, _Point):
|
|
136
138
|
if not isinstance(left, _Point) or not isinstance(right, _Point):
|
|
137
139
|
error_message = 'Selection cannot mix points and differences.'
|
|
138
|
-
raise
|
|
140
|
+
raise UnitOperationError(error_message)
|
|
139
141
|
if not left.unit._compatible_with(right.unit):
|
|
140
142
|
error_message = 'Selection requires compatible points with the same convention.'
|
|
141
143
|
raise DimensionError(error_message)
|
|
@@ -817,10 +819,13 @@ def dispatch_function(
|
|
|
817
819
|
np.amax,
|
|
818
820
|
np.nanmin,
|
|
819
821
|
np.nanmax,
|
|
822
|
+
np.diff,
|
|
823
|
+
np.gradient,
|
|
820
824
|
):
|
|
821
|
-
|
|
822
|
-
'This NumPy function
|
|
825
|
+
error_message = (
|
|
826
|
+
'This NumPy function does not support coordinate points; convert explicitly.'
|
|
823
827
|
)
|
|
828
|
+
raise TypeError(error_message)
|
|
824
829
|
if func in (np.isclose, np.allclose):
|
|
825
830
|
return _close_comparison(func, *args, **kwargs)
|
|
826
831
|
if func in (np.concatenate, np.stack):
|
|
@@ -1562,25 +1567,36 @@ def _diff(a: Any, n: int = 1, axis: int = -1, prepend: Any = _UNSET, append: Any
|
|
|
1562
1567
|
# Like NumPy, the no-op retains the input and ignores axis and boundaries.
|
|
1563
1568
|
if n == 0:
|
|
1564
1569
|
return a
|
|
1565
|
-
value, unit =
|
|
1570
|
+
value, unit = _operand_parts(a)
|
|
1566
1571
|
boundaries = {}
|
|
1567
1572
|
for name, boundary in (('prepend', prepend), ('append', append)):
|
|
1568
1573
|
if boundary is _UNSET:
|
|
1569
1574
|
continue
|
|
1570
1575
|
if not _is_supported_operand(boundary):
|
|
1571
1576
|
return NotImplemented
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
+
if isinstance(unit, _Coordinate):
|
|
1578
|
+
_, boundaries[name], _ = _selection_parts(a, boundary)
|
|
1579
|
+
else:
|
|
1580
|
+
raw, source = _linear_parts(boundary)
|
|
1581
|
+
if not compatible(source, unit):
|
|
1582
|
+
error_message = f'{name} has an incompatible dimension.'
|
|
1583
|
+
raise DimensionError(error_message)
|
|
1584
|
+
boundaries[name] = scale_magnitude(raw, source.factor / unit.factor)
|
|
1585
|
+
return Quantity(np.diff(value, n=n, axis=axis, **boundaries), _delta_unit(unit))
|
|
1577
1586
|
|
|
1578
1587
|
|
|
1579
1588
|
def _gradient(f: Any, *varargs: Any, axis: Any = None, edge_order: Literal[1, 2] = 1) -> Any:
|
|
1580
1589
|
if not all(_is_supported_operand(x) for x in (f, *varargs)):
|
|
1581
1590
|
return NotImplemented
|
|
1582
|
-
value, unit =
|
|
1583
|
-
|
|
1591
|
+
value, unit = _operand_parts(f)
|
|
1592
|
+
unit = _delta_unit(unit)
|
|
1593
|
+
spacings = []
|
|
1594
|
+
for coordinate in varargs:
|
|
1595
|
+
raw, source = _operand_parts(coordinate)
|
|
1596
|
+
if isinstance(source, _Coordinate) and np.ndim(raw) == 0:
|
|
1597
|
+
error_message = 'A scalar point is not a spacing step; use a Quantity difference.'
|
|
1598
|
+
raise UnitOperationError(error_message)
|
|
1599
|
+
spacings.append((raw, _delta_unit(source)))
|
|
1584
1600
|
result = np.gradient(value, *(x[0] for x in spacings), axis=axis, edge_order=edge_order)
|
|
1585
1601
|
# NumPy validates axes, coordinate shapes, and argument counts. Scalar
|
|
1586
1602
|
# spacing applies to every selected axis; otherwise each axis has its own.
|
|
@@ -1975,7 +1991,8 @@ def _affine_ufunc(ufunc: Any, method: str, inputs: tuple[Any, ...], kwargs: dict
|
|
|
1975
1991
|
from .._coordinates.points import _addition_parts, _compare
|
|
1976
1992
|
|
|
1977
1993
|
if method != '__call__':
|
|
1978
|
-
|
|
1994
|
+
error_message = 'Affine points cannot be accumulated or reduced with arithmetic ufuncs.'
|
|
1995
|
+
raise UnitOperationError(error_message)
|
|
1979
1996
|
if kwargs.keys() - {'where', 'dtype', 'casting', 'order', 'subok'}:
|
|
1980
1997
|
return NotImplemented
|
|
1981
1998
|
_validate_where(kwargs)
|
|
@@ -1984,7 +2001,8 @@ def _affine_ufunc(ufunc: Any, method: str, inputs: tuple[Any, ...], kwargs: dict
|
|
|
1984
2001
|
if 'where' in kwargs:
|
|
1985
2002
|
kwargs = {**kwargs, 'out': (None,) * ufunc.nout}
|
|
1986
2003
|
if any(isinstance(x, (_Coordinate, Unit)) for x in inputs):
|
|
1987
|
-
|
|
2004
|
+
error_message = 'Affine unit objects cannot participate in this ufunc.'
|
|
2005
|
+
raise UnitOperationError(error_message)
|
|
1988
2006
|
if 'where' in kwargs:
|
|
1989
2007
|
mask = kwargs['where']
|
|
1990
2008
|
inputs = tuple(
|
|
@@ -2022,7 +2040,8 @@ def _affine_ufunc(ufunc: Any, method: str, inputs: tuple[Any, ...], kwargs: dict
|
|
|
2022
2040
|
if ufunc in (np.minimum, np.maximum, np.fmin, np.fmax):
|
|
2023
2041
|
a, b, unit = _selection_parts(*inputs)
|
|
2024
2042
|
return _wrap(ufunc(a, b, **kwargs), unit)
|
|
2025
|
-
|
|
2043
|
+
error_message = 'This ufunc is undefined for affine points; convert to physical units first.'
|
|
2044
|
+
raise UnitOperationError(error_message)
|
|
2026
2045
|
|
|
2027
2046
|
|
|
2028
2047
|
def _extremum(
|
|
@@ -39,19 +39,28 @@ class WritableArray(Array, Protocol):
|
|
|
39
39
|
def __setitem__(self, key: Any, value: Any, /) -> None: ...
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
class
|
|
43
|
-
"""Capture
|
|
42
|
+
class _DTypeValue(Array, Protocol[_ScalarType]):
|
|
43
|
+
"""Capture a NumPy array/scalar dtype independently of its shape."""
|
|
44
44
|
|
|
45
45
|
@property
|
|
46
46
|
def dtype(self) -> _NumpyDTypeOf[_ScalarType]: ...
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
class _TypedArray(WritableArray, _DTypeValue[_ScalarType], Protocol[_ScalarType]):
|
|
50
|
+
"""Capture ndarray dtype without retaining the source shape parameter."""
|
|
51
|
+
|
|
52
|
+
|
|
49
53
|
if TYPE_CHECKING:
|
|
50
54
|
import numpy as np # pyright: ignore[reportMissingImports]
|
|
51
55
|
from numpy.typing import NDArray # pyright: ignore[reportMissingImports]
|
|
52
56
|
|
|
53
57
|
_NumpyScalar: TypeAlias = np.generic
|
|
58
|
+
_NumpyNumber: TypeAlias = np.number[Any]
|
|
59
|
+
_InexactScalar = TypeVar('_InexactScalar', bound=np.inexact[Any])
|
|
60
|
+
_FloatingScalar = TypeVar('_FloatingScalar', bound=np.floating[Any])
|
|
61
|
+
_ComplexScalar = TypeVar('_ComplexScalar', bound=np.complexfloating[Any, Any])
|
|
54
62
|
_NumpyArrayOf: TypeAlias = NDArray[_ScalarType]
|
|
63
|
+
_NumpyValueOf: TypeAlias = NDArray[_ScalarType] | _ScalarType
|
|
55
64
|
_NumpyDTypeOf: TypeAlias = np.dtype[_ScalarType]
|
|
56
65
|
NumpyArray: TypeAlias = NDArray[Any]
|
|
57
66
|
NumpyValue: TypeAlias = NumpyArray | np.number[Any]
|
|
@@ -59,7 +68,12 @@ if TYPE_CHECKING:
|
|
|
59
68
|
else:
|
|
60
69
|
# Keep annotations resolvable without importing an optional dependency.
|
|
61
70
|
type _NumpyArrayOf[S] = Array
|
|
71
|
+
type _NumpyValueOf[S] = Array
|
|
62
72
|
type _NumpyDTypeOf[S] = object
|
|
63
73
|
_NumpyScalar = object
|
|
74
|
+
_NumpyNumber = object
|
|
75
|
+
_InexactScalar = TypeVar('_InexactScalar')
|
|
76
|
+
_FloatingScalar = TypeVar('_FloatingScalar')
|
|
77
|
+
_ComplexScalar = TypeVar('_ComplexScalar')
|
|
64
78
|
NumpyArray = NumpyValue = Array
|
|
65
79
|
NumpyDType = object
|