MCPcopy Create free account
hub / github.com/PyTables/PyTables / _normalize_shape

Function _normalize_shape

tables/atom.py:87–103  ·  view source on GitHub ↗

Check that the `shape` is safe to be used and return it as a tuple.

(shape: Shape | np.integer | int)

Source from the content-addressed store, hash-verified

85
86
87def _normalize_shape(shape: Shape | np.integer | int) -> Shape:
88 """Check that the `shape` is safe to be used and return it as a tuple."""
89 if isinstance(shape, (np.integer, int)):
90 if shape < 1:
91 raise ValueError("shape value must be greater than 0: %d" % shape)
92 shape = (shape,) # N is a shorthand for (N,)
93 try:
94 shape = tuple(shape)
95 except TypeError:
96 raise TypeError(f"shape must be an integer or sequence: {shape!r}")
97
98 # XXX Get from HDF5 library if possible.
99 # HDF5 does not support ranks greater than 32
100 if len(shape) > 32:
101 raise ValueError(f"shapes with rank > 32 are not supported: {shape!r}")
102
103 return tuple(SizeType(s) for s in shape)
104
105
106def _normalize_default(value: Any, dtype: DTypeLike) -> np.ndarray:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected