Coverage for install/scipp/core/_sizes.py: 50%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3from collections.abc import Sequence
4from typing import TypedDict
7class DimsAndShape(TypedDict):
8 dims: Sequence[str]
9 shape: Sequence[int]
12def _parse_dims_shape_sizes(
13 dims: Sequence[str] | None = None,
14 shape: Sequence[int] | None = None,
15 sizes: dict[str, int] | None = None,
16) -> DimsAndShape:
17 if sizes is not None:
18 if dims is not None or shape is not None:
19 raise ValueError(
20 "When sizes is specified, dims and shape must "
21 f"both be None. Got dims: {dims}, shape: {shape}"
22 )
23 dims = list(sizes.keys())
24 shape = list(sizes.values())
25 else:
26 if dims is None or shape is None:
27 raise ValueError(
28 "Dims and shape are required when sizes are not specified."
29 )
30 return {"dims": dims, "shape": shape}