ansys-units 0.7.dev0__tar.gz → 0.8.dev0__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.
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/PKG-INFO +13 -12
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/pyproject.toml +35 -11
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/cfg.yaml +4 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/dimensions.py +5 -1
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity.py +73 -3
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/systems.py +1 -1
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/unit.py +2 -4
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/unit_registry.py +1 -1
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/LICENSE +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/README.rst +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/__init__.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/_constants.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/_version.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/base_dimensions.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/docs/.gitignore +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity_dimensions.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity_tables/bt_table.yaml +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity_tables/cgs_table.yaml +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity_tables/si_table.yaml +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/variable_descriptor/__init__.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/variable_descriptor/strategy.py +0 -0
- {ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/variable_descriptor/variable_descriptor.py +0 -0
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ansys-units
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.dev0
|
|
4
4
|
Summary: Pythonic interface for units, unit systems, and unit conversions.
|
|
5
5
|
Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
|
6
6
|
Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
|
7
|
-
Requires-Python: >=3.
|
|
7
|
+
Requires-Python: >=3.10,<3.14
|
|
8
8
|
Description-Content-Type: text/x-rst
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
10
10
|
Classifier: Intended Audience :: Science/Research
|
|
11
11
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
15
|
License-File: LICENSE
|
|
18
16
|
Requires-Dist: importlib-metadata>=4.0
|
|
19
17
|
Requires-Dist: pyyaml>=6.0
|
|
18
|
+
Requires-Dist: numpy==2.2.3 ; extra == "additional"
|
|
19
|
+
Requires-Dist: pydantic>=2.11.7 ; extra == "additional"
|
|
20
|
+
Requires-Dist: pydantic_core>=2.33.2 ; extra == "additional"
|
|
20
21
|
Requires-Dist: ansys-sphinx-theme==1.3.2 ; extra == "doc"
|
|
21
22
|
Requires-Dist: pdf2image==1.17.0 ; extra == "doc"
|
|
22
|
-
Requires-Dist: quarto-cli==1.7.
|
|
23
|
+
Requires-Dist: quarto-cli==1.7.32 ; extra == "doc"
|
|
23
24
|
Requires-Dist: matplotlib==3.10.1 ; extra == "doc"
|
|
24
|
-
Requires-Dist: numpydoc==1.
|
|
25
|
+
Requires-Dist: numpydoc==1.9.0 ; extra == "doc"
|
|
25
26
|
Requires-Dist: Sphinx==7.4.7 ; extra == "doc"
|
|
26
27
|
Requires-Dist: sphinx-copybutton==0.5.2 ; extra == "doc"
|
|
27
28
|
Requires-Dist: sphinx-gallery==0.19.0 ; extra == "doc"
|
|
28
29
|
Requires-Dist: sphinx-toggleprompt==0.6.0 ; extra == "doc"
|
|
29
|
-
Requires-Dist: numpy==2.2.3 ; extra == "
|
|
30
|
-
Requires-Dist: pytest==8.
|
|
31
|
-
Requires-Dist: pytest-cov==6.
|
|
32
|
-
Requires-Dist: pytest-mock==3.14.
|
|
30
|
+
Requires-Dist: numpy==2.2.3 ; extra == "tests"
|
|
31
|
+
Requires-Dist: pytest==8.4.1 ; extra == "tests"
|
|
32
|
+
Requires-Dist: pytest-cov==6.2.1 ; extra == "tests"
|
|
33
|
+
Requires-Dist: pytest-mock==3.14.1 ; extra == "tests"
|
|
33
34
|
Requires-Dist: pint==0.24.4 ; extra == "tests"
|
|
34
35
|
Project-URL: Documentation, https://ansunits.docs.pyansys.com
|
|
35
36
|
Project-URL: Issues, https://github.com/ansys/pyansys-units/issues
|
|
36
37
|
Project-URL: Releases, https://github.com/ansys/pyansys-units/releases
|
|
37
38
|
Project-URL: Source, https://github.com/ansys/pyansys-units
|
|
39
|
+
Provides-Extra: additional
|
|
38
40
|
Provides-Extra: doc
|
|
39
|
-
Provides-Extra: lists
|
|
40
41
|
Provides-Extra: tests
|
|
41
42
|
|
|
42
43
|
PyAnsys Units
|
|
@@ -5,10 +5,10 @@ build-backend = "flit_core.buildapi"
|
|
|
5
5
|
[project]
|
|
6
6
|
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
|
|
7
7
|
name = "ansys-units"
|
|
8
|
-
version = "0.
|
|
8
|
+
version = "0.8.dev0"
|
|
9
9
|
description = "Pythonic interface for units, unit systems, and unit conversions."
|
|
10
10
|
readme = "README.rst"
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.10,<3.14"
|
|
12
12
|
license = {file = "LICENSE"}
|
|
13
13
|
authors = [{name = "ANSYS, Inc.", email = "pyansys.core@ansys.com"}]
|
|
14
14
|
maintainers = [{name = "ANSYS, Inc.", email = "pyansys.core@ansys.com"}]
|
|
@@ -18,9 +18,7 @@ classifiers = [
|
|
|
18
18
|
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
19
19
|
"License :: OSI Approved :: MIT License",
|
|
20
20
|
"Operating System :: OS Independent",
|
|
21
|
-
"Programming Language :: Python :: 3
|
|
22
|
-
"Programming Language :: Python :: 3.10",
|
|
23
|
-
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
24
22
|
]
|
|
25
23
|
|
|
26
24
|
dependencies = [
|
|
@@ -32,22 +30,25 @@ dependencies = [
|
|
|
32
30
|
doc = [
|
|
33
31
|
"ansys-sphinx-theme==1.3.2",
|
|
34
32
|
"pdf2image==1.17.0",
|
|
35
|
-
"quarto-cli==1.7.
|
|
33
|
+
"quarto-cli==1.7.32",
|
|
36
34
|
"matplotlib==3.10.1",
|
|
37
|
-
"numpydoc==1.
|
|
35
|
+
"numpydoc==1.9.0",
|
|
38
36
|
"Sphinx==7.4.7",
|
|
39
37
|
"sphinx-copybutton==0.5.2",
|
|
40
38
|
"sphinx-gallery==0.19.0",
|
|
41
39
|
"sphinx-toggleprompt==0.6.0",
|
|
42
40
|
]
|
|
43
41
|
tests = [
|
|
44
|
-
"
|
|
45
|
-
"pytest
|
|
46
|
-
"pytest-
|
|
42
|
+
"numpy==2.2.3",
|
|
43
|
+
"pytest==8.4.1",
|
|
44
|
+
"pytest-cov==6.2.1",
|
|
45
|
+
"pytest-mock==3.14.1",
|
|
47
46
|
"pint==0.24.4",
|
|
48
47
|
]
|
|
49
|
-
|
|
48
|
+
additional = [
|
|
50
49
|
"numpy==2.2.3",
|
|
50
|
+
"pydantic>=2.11.7",
|
|
51
|
+
"pydantic_core>=2.33.2",
|
|
51
52
|
]
|
|
52
53
|
|
|
53
54
|
[project.urls]
|
|
@@ -93,3 +94,26 @@ source = ["ansys.units"]
|
|
|
93
94
|
|
|
94
95
|
[tool.coverage.report]
|
|
95
96
|
show_missing = true
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
[tool.bandit]
|
|
100
|
+
exclude_dirs = ["tests"]
|
|
101
|
+
skips = [
|
|
102
|
+
"B101",
|
|
103
|
+
"B105",
|
|
104
|
+
"B106",
|
|
105
|
+
"B110",
|
|
106
|
+
"B112",
|
|
107
|
+
"B301",
|
|
108
|
+
"B307",
|
|
109
|
+
"B310",
|
|
110
|
+
"B311",
|
|
111
|
+
"B314",
|
|
112
|
+
"B403",
|
|
113
|
+
"B404",
|
|
114
|
+
"B405",
|
|
115
|
+
"B602",
|
|
116
|
+
"B603",
|
|
117
|
+
"B604",
|
|
118
|
+
"B607",
|
|
119
|
+
]
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
# For micro, u is used instead of the Greek letter mu.
|
|
12
12
|
|
|
13
13
|
multipliers:
|
|
14
|
+
Q: 1.0e+30
|
|
15
|
+
R: 1.0e+27
|
|
14
16
|
Y: 1.0e+24
|
|
15
17
|
Z: 1.0e+21
|
|
16
18
|
E: 1.0e+18
|
|
@@ -31,6 +33,8 @@ multipliers:
|
|
|
31
33
|
a: 1.0e-18
|
|
32
34
|
z: 1.0e-21
|
|
33
35
|
y: 1.0e-24
|
|
36
|
+
r: 1.0e-27
|
|
37
|
+
q: 1.0e-30
|
|
34
38
|
|
|
35
39
|
# Unit Systems
|
|
36
40
|
# ------------
|
|
@@ -25,7 +25,7 @@ from __future__ import annotations
|
|
|
25
25
|
|
|
26
26
|
from typing import Union
|
|
27
27
|
|
|
28
|
-
from ansys.units import BaseDimensions
|
|
28
|
+
from ansys.units.base_dimensions import BaseDimensions
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class Dimensions:
|
|
@@ -128,6 +128,10 @@ class Dimensions:
|
|
|
128
128
|
def __bool__(self):
|
|
129
129
|
return bool(self._dimensions)
|
|
130
130
|
|
|
131
|
+
def __getitem__(self, key):
|
|
132
|
+
dimension_name = BaseDimensions[key]
|
|
133
|
+
return self._dimensions[dimension_name]
|
|
134
|
+
|
|
131
135
|
|
|
132
136
|
class IncorrectDimensions(ValueError):
|
|
133
137
|
"""Raised on initialization if a dimension is not of type ``BaseDimensions``."""
|
|
@@ -27,7 +27,8 @@ from collections.abc import Iterable
|
|
|
27
27
|
import operator
|
|
28
28
|
from typing import Union
|
|
29
29
|
|
|
30
|
-
from ansys.units import BaseDimensions
|
|
30
|
+
from ansys.units.base_dimensions import BaseDimensions
|
|
31
|
+
from ansys.units.dimensions import Dimensions
|
|
31
32
|
from ansys.units.systems import UnitSystem
|
|
32
33
|
from ansys.units.unit import Unit
|
|
33
34
|
|
|
@@ -38,6 +39,13 @@ try:
|
|
|
38
39
|
except ImportError:
|
|
39
40
|
_array = None
|
|
40
41
|
|
|
42
|
+
try:
|
|
43
|
+
from pydantic_core import core_schema
|
|
44
|
+
|
|
45
|
+
_core_schema = core_schema
|
|
46
|
+
except ImportError:
|
|
47
|
+
_core_schema = None
|
|
48
|
+
|
|
41
49
|
try:
|
|
42
50
|
from matplotlib.units import AxisInfo, ConversionInterface, registry
|
|
43
51
|
|
|
@@ -91,6 +99,7 @@ class Quantity:
|
|
|
91
99
|
quantity_table: dict = None,
|
|
92
100
|
dimensions: Dimensions = None,
|
|
93
101
|
copy_from: Quantity = None,
|
|
102
|
+
**kwargs,
|
|
94
103
|
):
|
|
95
104
|
if (
|
|
96
105
|
(units and quantity_table)
|
|
@@ -133,10 +142,12 @@ class Quantity:
|
|
|
133
142
|
if not isinstance(units, Unit):
|
|
134
143
|
units = Unit(units)
|
|
135
144
|
|
|
145
|
+
min_value = value if isinstance(value, (int, float)) else min(value)
|
|
146
|
+
|
|
136
147
|
if (
|
|
137
148
|
(units.name in ["K", "R"] and value < 0)
|
|
138
|
-
or (units.name == "C" and
|
|
139
|
-
or (units.name == "F" and
|
|
149
|
+
or (units.name == "C" and min_value < -273.15)
|
|
150
|
+
or (units.name == "F" and min_value < -459.67)
|
|
140
151
|
):
|
|
141
152
|
units = Unit(f"delta_{units.name}")
|
|
142
153
|
|
|
@@ -147,6 +158,8 @@ class Quantity:
|
|
|
147
158
|
self._value = self.to(unit).value
|
|
148
159
|
self._unit = unit
|
|
149
160
|
|
|
161
|
+
self.extra_fields = kwargs
|
|
162
|
+
|
|
150
163
|
@classmethod
|
|
151
164
|
def preferred_units(
|
|
152
165
|
cls, units: list[Union[Unit, str]], remove: bool = False
|
|
@@ -446,6 +459,54 @@ class Quantity:
|
|
|
446
459
|
def __ne__(self, other):
|
|
447
460
|
return not self.__eq__(other)
|
|
448
461
|
|
|
462
|
+
@classmethod
|
|
463
|
+
def __get_pydantic_core_schema__(cls, source_type, handler):
|
|
464
|
+
"""Define the pydantic core schema for QuantityPydanticAdapter."""
|
|
465
|
+
|
|
466
|
+
def validate_quantity_type(obj):
|
|
467
|
+
if isinstance(obj, cls):
|
|
468
|
+
return obj
|
|
469
|
+
if isinstance(obj, Quantity):
|
|
470
|
+
return cls(
|
|
471
|
+
value=(
|
|
472
|
+
obj._value.tolist()
|
|
473
|
+
if hasattr(obj._chosen_unitsvalue, "tolist")
|
|
474
|
+
else obj.value
|
|
475
|
+
),
|
|
476
|
+
units=obj.units.name,
|
|
477
|
+
)
|
|
478
|
+
if isinstance(obj, dict):
|
|
479
|
+
value = obj.get("value")
|
|
480
|
+
units = obj.get("units")
|
|
481
|
+
extras = {k: v for k, v in obj.items() if k not in {"value", "units"}}
|
|
482
|
+
return cls(value=value, units=units, **extras)
|
|
483
|
+
raise TypeError(
|
|
484
|
+
"Expected dict, Quantity, or QuantityPydanticAdapter instance."
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
def serialize(instance):
|
|
488
|
+
base = {"value": instance.value, "units": instance.units.name}
|
|
489
|
+
return {**base, **instance.extra_fields}
|
|
490
|
+
|
|
491
|
+
if _core_schema is None:
|
|
492
|
+
raise PydanticRequired()
|
|
493
|
+
|
|
494
|
+
return _core_schema.no_info_plain_validator_function(
|
|
495
|
+
validate_quantity_type,
|
|
496
|
+
json_schema_input_schema=_core_schema.model_fields_schema(
|
|
497
|
+
{
|
|
498
|
+
"value": _core_schema.list_schema(
|
|
499
|
+
items_schema=_core_schema.float_schema()
|
|
500
|
+
),
|
|
501
|
+
"units": _core_schema.str_schema(),
|
|
502
|
+
},
|
|
503
|
+
extras_schema=_core_schema.any_schema(),
|
|
504
|
+
),
|
|
505
|
+
serialization=_core_schema.plain_serializer_function_ser_schema(
|
|
506
|
+
serialize, return_schema=_core_schema.dict_schema()
|
|
507
|
+
),
|
|
508
|
+
)
|
|
509
|
+
|
|
449
510
|
|
|
450
511
|
def get_si_value(quantity: Quantity) -> float:
|
|
451
512
|
"""Returns a quantity's value in SI units."""
|
|
@@ -510,6 +571,15 @@ class NumPyRequired(ModuleNotFoundError):
|
|
|
510
571
|
super().__init__("To use NumPy arrays and lists install NumPy.")
|
|
511
572
|
|
|
512
573
|
|
|
574
|
+
class PydanticRequired(ModuleNotFoundError):
|
|
575
|
+
"""Raised when pydantic or pydantic_core is unavailable."""
|
|
576
|
+
|
|
577
|
+
def __init__(self):
|
|
578
|
+
super().__init__(
|
|
579
|
+
"To use pydantic features, install it using 'pip install ansys-units[additional]'."
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
|
|
513
583
|
class InvalidFloatUsage(FloatingPointError):
|
|
514
584
|
"""Raised when float is unsupported for given type of quantity."""
|
|
515
585
|
|
|
@@ -25,16 +25,14 @@ from __future__ import annotations
|
|
|
25
25
|
import os
|
|
26
26
|
from typing import Optional, Union
|
|
27
27
|
|
|
28
|
-
from ansys.units import (
|
|
29
|
-
BaseDimensions,
|
|
30
|
-
Dimensions,
|
|
31
|
-
)
|
|
32
28
|
from ansys.units._constants import (
|
|
33
29
|
_base_units,
|
|
34
30
|
_derived_units,
|
|
35
31
|
_multipliers,
|
|
36
32
|
_quantity_units_table,
|
|
37
33
|
)
|
|
34
|
+
from ansys.units.base_dimensions import BaseDimensions
|
|
35
|
+
from ansys.units.dimensions import Dimensions
|
|
38
36
|
from ansys.units.systems import UnitSystem
|
|
39
37
|
|
|
40
38
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/quantity_tables/cgs_table.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/variable_descriptor/__init__.py
RENAMED
|
File without changes
|
{ansys_units-0.7.dev0 → ansys_units-0.8.dev0}/src/ansys/units/variable_descriptor/strategy.py
RENAMED
|
File without changes
|
|
File without changes
|