typespecs package#

class typespecs.ItselfType[source]#

Bases: object

Sentinel object specifying metadata-stripped annotation itself.

class typespecs.Spec(*args: Any, **kwargs: Any)[source]#

Bases: ReadonlyDict[str, Any]

Type specification.

This is a subclass of the read-only dictionary without any runtime modifications. It is intended to distinguish a type specification from other type metadata.

class typespecs.SpecFrame(data=None, index: Axes | None = None, columns: Axes | None = None, dtype: Dtype | None = None, copy: bool | None = None)[source]#

Bases: DataFrame

Specification DataFrame.

This is a subclass of the pandas DataFrame without any runtime modifications. It is intended to distinguish a specification DataFrame from other DataFrames.

typespecs.from_annotated(obj: Any, /, data: str | None = 'data', default: dict[str, ~typing.Any] | ~typing.Any=<NA>, merge: bool = True, separator: str = '/', type: str | None = 'type') SpecFrame[source]#

Create a specification DataFrame from given object with annotations.

Parameters:
  • obj – The object to convert.

  • data – Name of the column for the actual data of the annotations. If it is None, the data column will not be created.

  • default – Default value for each column. Either a single value or a dictionary mapping column names to values is accepted.

  • merge – Whether to merge all sub-annotations into a single row. If it is False, each sub-annotation will have its own row.

  • separator – Separator for concatenating root and sub-indices.

  • type – Name of the column for the metadata-stripped annotations. If it is None, the type column will not be created.

Returns:

Created specification DataFrame.

typespecs.from_annotation(obj: Any, /, *, default: dict[str, ~typing.Any] | ~typing.Any=<NA>, index: str = 'root', merge: bool = True, separator: str = '/', type: str | None = 'type') SpecFrame[source]#

Create a specification DataFrame from given annotation.

Parameters:
  • obj – The annotation to convert.

  • default – Default value for each column. Either a single value or a dictionary mapping column names to values is accepted.

  • index – Root index of the created specification DataFrame.

  • merge – Whether to merge all sub-annotations into a single row. If it is False, each sub-annotation will have its own row.

  • separator – Separator for concatenating root and sub-indices.

  • type – Name of the column for the metadata-stripped annotations. If it is None, the type column will not be created.

Returns:

Created specification DataFrame.

typespecs.from_annotations(obj: dict[str, ~typing.Any], /, *, default: dict[str, ~typing.Any] | ~typing.Any = <NA>, merge: bool = True, separator: str = '/', type: str | None = 'type') SpecFrame[source]#

Create a specification DataFrame from given annotations.

Parameters:
  • obj – The annotations to convert.

  • default – Default value for each column. Either a single value or a dictionary mapping column names to values is accepted.

  • merge – Whether to merge all sub-annotations into a single row. If it is False, each sub-annotation will have its own row.

  • separator – Separator for concatenating root and sub-indices.

  • type – Name of the column for the metadata-stripped annotations. If it is None, the type column will not be created.

Returns:

Created specification DataFrame.

Submodules#