Create an Atom from a PyTables type. Optional shape and default value may be specified as the shape and dflt arguments, respectively:: >>> Atom.from_type('bool') BoolAtom(shape=(), dflt=False) >>> Atom.from_type('int16', shape=(2, 2))
(
cls, type_: str, shape: Shape = (), dflt: Any = None
)
| 391 | |
| 392 | @classmethod |
| 393 | def from_type( |
| 394 | cls, type_: str, shape: Shape = (), dflt: Any = None |
| 395 | ) -> Atom: |
| 396 | """Create an Atom from a PyTables type. |
| 397 | |
| 398 | Optional shape and default value may be specified as the |
| 399 | shape and dflt arguments, respectively:: |
| 400 | |
| 401 | >>> Atom.from_type('bool') |
| 402 | BoolAtom(shape=(), dflt=False) |
| 403 | >>> Atom.from_type('int16', shape=(2, 2)) |
| 404 | Int16Atom(shape=(2, 2), dflt=0) |
| 405 | >>> Atom.from_type('string40', dflt='hello') |
| 406 | Traceback (most recent call last): |
| 407 | ... |
| 408 | ValueError: unknown type: 'string40' |
| 409 | >>> Atom.from_type('Float64') |
| 410 | Traceback (most recent call last): |
| 411 | ... |
| 412 | ValueError: unknown type: 'Float64' |
| 413 | |
| 414 | """ |
| 415 | if type_ not in all_types: |
| 416 | raise ValueError(f"unknown type: {type_!r}") |
| 417 | kind, itemsize = split_type(type_) |
| 418 | return cls.from_kind(kind, itemsize, shape, dflt) |
| 419 | |
| 420 | @classmethod |
| 421 | def from_kind( |