Skip to content

Base

Attributes Types

oqd_dataschema.base

AttrKey = Annotated[str, BeforeValidator(_valid_attr_key)] module-attribute

Annotated type that represents a valid key for attributes (prevents overwriting of protected attrs).

Attrs = dict[AttrKey, Union[int, float, str, complex]] module-attribute

Type that represents attributes of an object.

Data Types

oqd_dataschema.base

DTypeNames = Literal[DTypes.names()] module-attribute

Literal list of lowercase names for DTypes variants.

DTypes

Bases: Enum

Enum for data types supported by oqd-dataschema.

Type Variant
Boolean BOOL
Integer INT16, INT32, INT64 (signed)
UINT16, UINT32, UINT64 (unsigned)
Float FLOAT32, FLOAT64
Complex COMPLEX64, COMPLEX128
Bytes BYTES
String STR, STRING
Source code in oqd-dataschema/src/oqd_dataschema/base.py
class DTypes(Enum):
    """
    Enum for data types supported by oqd-dataschema.

    |Type   |Variant|
    |-------|-------|
    |Boolean|`BOOL` |
    |Integer|`INT16`, `INT32`, `INT64` (signed)<br>`UINT16`, `UINT32`, `UINT64` (unsigned)|
    |Float  |`FLOAT32`, `FLOAT64`|
    |Complex|`COMPLEX64`, `COMPLEX128`|
    |Bytes  |`BYTES`|
    |String |`STR`, `STRING`|
    """

    BOOL = np.dtypes.BoolDType
    INT16 = np.dtypes.Int16DType
    INT32 = np.dtypes.Int32DType
    INT64 = np.dtypes.Int64DType
    UINT16 = np.dtypes.UInt16DType
    UINT32 = np.dtypes.UInt32DType
    UINT64 = np.dtypes.UInt64DType
    FLOAT16 = np.dtypes.Float16DType
    FLOAT32 = np.dtypes.Float32DType
    FLOAT64 = np.dtypes.Float64DType
    COMPLEX64 = np.dtypes.Complex64DType
    COMPLEX128 = np.dtypes.Complex128DType
    STR = np.dtypes.StrDType
    BYTES = np.dtypes.BytesDType
    STRING = np.dtypes.StringDType

    @classmethod
    def get(cls, name: str) -> DTypes:
        """
        Get the [`DTypes`][oqd_dataschema.base.DTypes] enum variant by lowercase name.
        """
        return cls[name.upper()]

    @classmethod
    def names(cls):
        """
        Get the lowercase names of all variants of [`DTypes`][oqd_dataschema.base.DTypes] enum.
        """
        return tuple((dtype.name.lower() for dtype in cls))
get(name: str) -> DTypes classmethod

Get the DTypes enum variant by lowercase name.

Source code in oqd-dataschema/src/oqd_dataschema/base.py
@classmethod
def get(cls, name: str) -> DTypes:
    """
    Get the [`DTypes`][oqd_dataschema.base.DTypes] enum variant by lowercase name.
    """
    return cls[name.upper()]
names() classmethod

Get the lowercase names of all variants of DTypes enum.

Source code in oqd-dataschema/src/oqd_dataschema/base.py
@classmethod
def names(cls):
    """
    Get the lowercase names of all variants of [`DTypes`][oqd_dataschema.base.DTypes] enum.
    """
    return tuple((dtype.name.lower() for dtype in cls))