Skip to content

Commit 788360e

Browse files
authored
Flesh out readme (#80)
1 parent ebc890f commit 788360e

File tree

9 files changed

+82
-15
lines changed

9 files changed

+82
-15
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: trailing-whitespace
77
- id: no-commit-to-branch
88
- repo: https://github.com/astral-sh/ruff-pre-commit
9-
rev: v0.11.2
9+
rev: v0.11.5
1010
hooks:
1111
- id: ruff
1212
args: [--fix, --exit-non-zero-on-fix]

Diff for: README.rst

+43-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,54 @@
1515
fast-array-utils
1616
================
1717

18-
To use ``fast_array_utils.stats`` or ``fast_array_tils.conv``:
18+
.. begin
19+
20+
usage
21+
-----
22+
23+
``fast-array-utils`` supports the following array types:
24+
25+
- ``numpy.ndarray``
26+
- ``scipy.sparse.cs{rc}_{array,matrix}``
27+
- ``cupy.ndarray`` and ``cupyx.scipy.sparse.cs{rc}_matrix``
28+
- ``dask.array.Array``
29+
- ``h5py.Dataset`` and ``zarr.Array``
30+
- ``anndata.abc.CS{CR}Dataset`` (only supported by ``.conv.to_dense`` at the moment)
31+
32+
Use ``fast_array_utils.conv.to_dense`` to densify arrays and optionally move them to CPU memory:
33+
34+
.. code:: python
35+
36+
from fast_array_utils.conv import to_dense
37+
38+
numpy_arr = to_dense(sparse_arr_or_mat)
39+
numpy_arr = to_dense(dask_or_cuda_arr, to_cpu_memory=True)
40+
dense_dask_arr = to_dense(dask_arr)
41+
dense_cupy_arr = to_dense(sparse_cupy_mat)
42+
43+
Use ``fast_array_utils.conv.*`` to calculate statistics across one or both axes of a 2D array.
44+
All of them support an `axis` and `dtype` parameter:
45+
46+
.. code:: python
47+
48+
from fast_array_utils import stats
49+
50+
all_equal = stats.is_constant(arr_2d)
51+
col_sums = stats.sum(arr_2d, axis=0)
52+
mean = stats.mean(arr_2d)
53+
row_means, row_vars = stats.mean_var(arr_2d, axis=1)
54+
55+
installation
56+
------------
57+
58+
To use ``fast_array_utils.stats`` or ``fast_array_utils.conv``:
1959

2060
.. code:: bash
2161
22-
[uv] pip install fast-array-utils[accel]
62+
(uv) pip install 'fast-array-utils[accel]'
2363
2464
To use ``testing.fast_array_utils``:
2565

2666
.. code:: bash
2767
28-
[uv] pip install fast-array-utils[testing]
68+
(uv) pip install 'fast-array-utils[testing]'

Diff for: docs/index.rst

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212

1313
.. automodule:: fast_array_utils
1414
:members:
15+
16+
See also the test utilities in :mod:`testing.fast_array_utils`.
17+
18+
.. include:: ../README.rst
19+
:start-after: .. begin

Diff for: pyproject.toml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[build-system]
22
build-backend = "hatchling.build"
3-
requires = [ "hatch-docstring-description", "hatch-vcs", "hatchling" ]
3+
requires = [ "hatch-docstring-description>=1.1.1", "hatch-fancy-pypi-readme", "hatch-vcs", "hatchling" ]
44

55
[project]
66
name = "fast-array-utils"
7-
readme = "README.rst"
87
license = "MPL-2.0"
98
authors = [
109
{ name = "Philipp A.", email = "[email protected]" },
@@ -18,7 +17,7 @@ classifiers = [
1817
"Programming Language :: Python :: 3.12",
1918
"Programming Language :: Python :: 3.13",
2019
]
21-
dynamic = [ "description", "version" ]
20+
dynamic = [ "description", "readme", "version" ]
2221
dependencies = [ "numpy" ]
2322
optional-dependencies.accel = [ "numba" ]
2423
optional-dependencies.doc = [
@@ -55,8 +54,13 @@ entry-points.pytest11.fast_array_utils = "testing.fast_array_utils.pytest"
5554
source = "vcs"
5655
raw-options = { local_scheme = "no-local-version" } # be able to publish dev version
5756

58-
# TODO: support setting main package in the plugin
59-
# [tool.hatch.metadata.hooks.docstring-description]
57+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
58+
content-type = "text/x-rst"
59+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
60+
path = "README.rst"
61+
start-after = ".. begin"
62+
63+
[tool.hatch.metadata.hooks.docstring-description]
6064

6165
[tool.hatch.build.targets.wheel]
6266
packages = [ "src/testing", "src/fast_array_utils" ]

Diff for: src/testing/fast_array_utils/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: MPL-2.0
2-
"""Testing utilities."""
2+
"""Testing utilities.
3+
4+
Ideally used through the :mod:`testing.fast_array_utils.pytest` plugin.
5+
"""
36

47
from __future__ import annotations
58

Diff for: src/testing/fast_array_utils/_array_type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def random_mat(
391391
container: Literal["array", "matrix"] = "array",
392392
rng: np.random.Generator | None = None,
393393
) -> types.CSBase:
394-
"""Create a random matrix."""
394+
"""Create a random sparse matrix/array."""
395395
from scipy.sparse import random as random_spmat
396396
from scipy.sparse import random_array as random_sparr
397397

Diff for: src/testing/fast_array_utils/pytest.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _skip_if_unimportable(array_type: ArrayType) -> pytest.MarkDecorator:
9797
def array_type(request: pytest.FixtureRequest, tmp_path: Path) -> Generator[ArrayType, None, None]:
9898
"""Fixture for a supported :class:`~testing.fast_array_utils.ArrayType`.
9999
100-
Use :class:`testing.fast_array_utils.Flags` to select or skip array types
100+
Use :class:`testing.fast_array_utils.Flags` to select or skip array types:
101101
102102
#. using ``select=``/``args[0]``:
103103
@@ -114,6 +114,21 @@ def test_something(array_type: ArrayType) -> None:
114114
@pytest.mark.array_type(skip=Flags.Dask | Flags.Disk | Flags.Gpu)
115115
def test_something(array_type: ArrayType) -> None:
116116
...
117+
118+
For special cases, you can also specify a :class:`set` of array types and flags.
119+
This is useful if you want to select or skip only specific array types.
120+
121+
.. code:: python
122+
123+
from testing.fast_array_utils import SUPPORTED_TYPES
124+
125+
SPARSE_AND_DASK = {
126+
at for at in SUPPORTED_TYPES if at.flags & Flags.Sparse and at.flags & Flags.Dask
127+
}
128+
129+
@pytest.mark.array_type(skip={*SPARSE_AND_DASK, Flags.Disk})
130+
def test_something(array_type: ArrayType) -> None:
131+
...
117132
"""
118133
at = cast("ArrayType", request.param)
119134
f: h5py.File | None = None

Diff for: tests/test_numpy_scipy_sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_ndim(array_type: ArrayType[types.CSBase, None]) -> None:
3232

3333
@numba.njit(cache=True)
3434
def mat_shape(mat: types.CSBase) -> tuple[int, ...]:
35-
return np.shape(mat) # type: ignore[arg-type]
35+
return np.shape(mat)
3636

3737

3838
@pytest.mark.array_type(select=Flags.Sparse, skip=Flags.Dask | Flags.Disk | Flags.Gpu)

Diff for: tests/test_stats.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_sum(
100100
assert sum_.dtype == dtype_in
101101

102102
expected = np.sum(np_arr, axis=axis, dtype=dtype_arg)
103-
np.testing.assert_array_equal(sum_, expected) # type: ignore[arg-type]
103+
np.testing.assert_array_equal(sum_, expected)
104104

105105

106106
@pytest.mark.array_type(skip=ATS_SPARSE_DS)
@@ -143,7 +143,7 @@ def test_mean_var(
143143
mean, var = mean.compute(), var.compute() # type: ignore[assignment]
144144
if isinstance(mean, types.CupyArray) and isinstance(var, types.CupyArray):
145145
mean, var = mean.get(), var.get()
146-
np.testing.assert_array_equal(mean, mean_expected) # type: ignore[arg-type]
146+
np.testing.assert_array_equal(mean, mean_expected)
147147
np.testing.assert_array_almost_equal(var, var_expected) # type: ignore[arg-type]
148148

149149

0 commit comments

Comments
 (0)