Skip to content

Commit 91bd420

Browse files
authored
pint -> quantity (#20)
1 parent 1a29dd9 commit 91bd420

File tree

7 files changed

+46
-40
lines changed

7 files changed

+46
-40
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
cache: true
3838
environments: ${{ matrix.environment }}
3939

40-
- name: pint-array tests
40+
- name: quantity-array tests
4141
run: pixi run --environment=${{ matrix.environment }} tests
4242

4343
- name: array-api-tests

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# pint-array
1+
# quantity-array
22

3-
Pint quantities with array API standard arrays.
3+
Quantities with array API standard arrays.
44

5-
hgrecco/pint#2101
5+
Currently based on [`pint`](https://github.com/hgrecco/pint), with a view to
6+
consuming a standardised Quantity API - see
7+
https://github.com/quantity-dev/discussions.

pixi.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,30 @@ build-backend = "hatchling.build"
55
[project]
66
authors = [
77
{ name = "Lucas Colley", email = "[email protected]" },
8+
# { name = "Open Source Contributors" }, # https://github.com/pypi/warehouse/issues/14813
89
]
9-
name = "pint-array"
10-
description = "Pint quantities with array API standard arrays."
10+
name = "quantity-array"
11+
description = "Quantities with array API standard arrays."
1112
readme = "README.md"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: OS Independent",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3 :: Only",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
]
1224
dynamic = ["version"]
1325
requires-python = ">=3.10"
1426

1527
[project.urls]
16-
Homepage = "https://github.com/lucascolley/pint-array"
28+
Homepage = "https://github.com/quantity-dev/quantity-array"
1729

1830
[tool.hatch]
19-
version.path = "src/pint_array/__init__.py"
31+
version.path = "src/quantity_array/__init__.py"
2032

2133
[tool.pixi.project]
2234
channels = ["https://prefix.dev/conda-forge"]
@@ -28,7 +40,7 @@ array-api-compat = ">=1.10.0,<2"
2840
array-api-strict = ">=2.2,<3"
2941

3042
[tool.pixi.pypi-dependencies]
31-
pint-array = { path = ".", editable = true }
43+
quantity-array = { path = ".", editable = true }
3244

3345
[tool.pixi.feature.dev.dependencies]
3446
ipython = ">=8.31.0,<9"
@@ -91,7 +103,7 @@ xp-tests.cmd = [
91103
"--disable-deadline",
92104
"array_api_tests/",
93105
]
94-
xp-tests.env.ARRAY_API_TESTS_MODULE = "pint_array.array_api_strict"
106+
xp-tests.env.ARRAY_API_TESTS_MODULE = "quantity_array.array_api_strict"
95107
xp-tests.cwd = "array-api-tests"
96108
xp-tests.depends-on = ["clone-xp-tests"]
97109

@@ -109,7 +121,7 @@ ci-py313 = ["py313", "tests", "xp-tests"]
109121

110122
[tool.ruff]
111123
target-version = "py310"
112-
exclude = ["src/pint_array/funcs.py"]
124+
exclude = ["src/quantity_array/funcs.py"]
113125

114126
[tool.ruff.lint]
115127
extend-select = [

src/pint_array/__init__.py renamed to src/quantity_array/__init__.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
pint_array
3-
~~~~~~~~~~
4-
5-
Pint interoperability with array API standard arrays.
6-
"""
1+
"""Quantities with array API standard arrays."""
72

83
import collections
94
import contextlib
@@ -20,21 +15,21 @@
2015
from pint.facets.plain import MagnitudeT, PlainQuantity
2116

2217
__version__ = "0.0.1.dev0"
23-
__all__ = ["__version__", "pint_namespace"]
18+
__all__ = ["__version__", "quantity_namespace"]
2419

2520

2621
def __getattr__(name):
2722
try:
2823
xp = importlib.import_module(name)
29-
mod = pint_namespace(xp)
24+
mod = quantity_namespace(xp)
3025
sys.modules[f"marray.{name}"] = mod
3126
return mod
3227
except ModuleNotFoundError as e:
3328
raise AttributeError(str(e)) from None
3429

3530

36-
def pint_namespace(xp):
37-
mod = types.ModuleType(f"pint({xp.__name__})")
31+
def quantity_namespace(xp):
32+
mod = types.ModuleType(f"quantity({xp.__name__})")
3833

3934
class ArrayQuantity(Generic[MagnitudeT], PlainQuantity[MagnitudeT]):
4035
def __init__(self, *args, **kwargs): # noqa: ARG002
@@ -695,11 +690,10 @@ def fun(x, /, *args, func_str=func_str, **kwargs):
695690

696691
setattr(mod, func_str, fun)
697692

698-
699693
def _sqrt(x, /, *args, **kwargs):
700694
x = asarray(x)
701695
magnitude = xp.asarray(x.magnitude, copy=True)
702-
magnitude = getattr(xp, "sqrt")(magnitude, *args, **kwargs)
696+
magnitude = xp.sqrt(magnitude, *args, **kwargs)
703697
return ArrayUnitQuantity(magnitude, x.units**0.5)
704698

705699
mod.sqrt = _sqrt
@@ -785,9 +779,7 @@ def pow(x1, x2, /, *args, **kwargs):
785779
if x1.unitless:
786780
units = "dimensionless"
787781
elif not xp.all(x2_magnitude == x2_first_elem_magnitude):
788-
extra_msg = (
789-
"The first array must be unitless, or the exponent must be a scalar or an array of all the same value."
790-
)
782+
extra_msg = "The first array must be unitless, or the exponent must be a scalar or an array of all the same value."
791783
raise DimensionalityError(
792784
x2.units,
793785
"dimensionless",
@@ -837,9 +829,9 @@ def matrix_transpose(x):
837829
def _sort(x, /, **kwargs):
838830
x = asarray(x)
839831
magnitude = xp.asarray(x.magnitude, copy=True)
840-
xp_func = getattr(xp, "sort")
832+
xp_func = xp.sort
841833
magnitude = xp_func(magnitude, **kwargs)
842-
units = x.units
834+
units = x.units
843835
return ArrayUnitQuantity(magnitude, units)
844836

845837
mod.sort = _sort
@@ -960,7 +952,7 @@ def clip(x, /, min=None, max=None):
960952
preface = [
961953
"The following is the documentation for the corresponding "
962954
f"attribute of `{xp.__name__}`.",
963-
"The behavior on pint-wrapped arrays is the same for dimensionless "
955+
"The behavior on quantity-wrapped arrays is the same for dimensionless "
964956
"quantities, and may differ for quantities with units.\n\n",
965957
]
966958
preface = "\n".join(preface)

tests/test_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from pint import DimensionalityError, OffsetUnitCalculusError
88
from pint.testsuite import helpers
99

10-
import pint_array
10+
import quantity_array
1111

12-
pxp = pint_array.pint_namespace(xp)
12+
pxp = quantity_array.quantity_namespace(xp)
1313

1414

1515
class TestArrayMethods:
@@ -451,7 +451,7 @@ def test_meshgrid_numpy_func(self):
451451
def test_comparisons(self):
452452
self.assertNDArrayEqual(
453453
pxp.asarray(self.q) > 2 * self.ureg.m,
454-
xp.asarray([[False, False], [True, True]])
454+
xp.asarray([[False, False], [True, True]]),
455455
)
456456
self.assertNDArrayEqual(
457457
pxp.asarray(self.q) < 2 * self.ureg.m,

tests/test_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import importlib.metadata
22

3-
import pint_array
3+
import quantity_array
44

55

66
def test_version():
7-
assert importlib.metadata.version("pint_array") == pint_array.__version__
7+
assert importlib.metadata.version("quantity_array") == quantity_array.__version__

0 commit comments

Comments
 (0)