Skip to content

Commit 2b33f65

Browse files
committed
Docstring for validate_shapes
1 parent 830ce25 commit 2b33f65

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

data_prototype/containers.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,41 @@ def validate_shapes(
4848
specification: dict[str, ShapeSpec | "Desc"],
4949
actual: dict[str, ShapeSpec | "Desc"],
5050
*,
51-
broadcast=False,
52-
) -> bool:
51+
broadcast: bool = False,
52+
) -> None:
53+
"""Validate specified shape relationships against a provided set of shapes.
54+
55+
Shapes provided are tuples of int | str. If a specification calls for an int,
56+
the exact size is expected.
57+
If it is a str, it must be a single capital letter optionally followed by ``+``
58+
or ``-`` an integer value.
59+
The same letter used in the specification must represent the same value in all
60+
appearances. The value may, however, be a variable (with an offset) in the
61+
actual shapes (which does not need to have the same letter).
62+
63+
Shapes may be provided as raw tuples or as ``Desc`` objects.
64+
65+
Parameters
66+
----------
67+
specification: dict[str, ShapeSpec | "Desc"]
68+
The desired shape relationships
69+
actual: dict[str, ShapeSpec | "Desc"]
70+
The shapes to test for compliance
71+
72+
Keyword Parameters
73+
------------------
74+
broadcast: bool
75+
Whether to allow broadcasted shapes to pass (i.e. actual shapes with a ``1``
76+
will not cause exceptions regardless of what the specified shape value is)
77+
78+
Raises
79+
------
80+
KeyError:
81+
If a required field from the specification is missing in the provided actual
82+
values.
83+
ValueError:
84+
If shapes are incompatible in any other way
85+
"""
5386
specvars: dict[str, int | tuple[str, int]] = {}
5487
for fieldname in specification:
5588
spec = specification[fieldname]

0 commit comments

Comments
 (0)