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

Function _normalize_default

tables/atom.py:106–125  ·  view source on GitHub ↗

Return `value` as a valid default of NumPy type `dtype`.

(value: Any, dtype: DTypeLike)

Source from the content-addressed store, hash-verified

104
105
106def _normalize_default(value: Any, dtype: DTypeLike) -> np.ndarray:
107 """Return `value` as a valid default of NumPy type `dtype`."""
108 # Create NumPy objects as defaults
109 # This is better in order to serialize them as attributes
110 if value is None:
111 value = 0
112 basedtype = dtype.base
113 try:
114 default = np.array(value, dtype=basedtype)
115 except ValueError:
116 array = np.array(value)
117 if array.shape != basedtype.shape:
118 raise
119 # Maybe nested dtype with "scalar" value.
120 default = np.array(value, dtype=basedtype.base)
121 # 0-dim arrays will be representented as NumPy scalars
122 # (PyTables attribute convention)
123 if default.shape == ():
124 default = default[()]
125 return default
126
127
128def _cmp_dispatcher(other_method_name: str) -> Callable[[Any, Any], bool]:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected