typeddfs.builders

Defines a builder pattern for TypedDf.

Module Contents

class typeddfs.builders.AffinityMatrixDfBuilder(name: str, doc: Optional[str] = None)

A builder pattern for typeddfs.matrix_dfs.AffinityMatrixDf.

Constructs a new builder.

Parameters
  • name – The name of the resulting class

  • doc – The docstring of the resulting class

Raises

TypeError – If name or doc non-string

build(self) Type[typeddfs.matrix_dfs.AffinityMatrixDf]

Builds this type.

Returns

A newly created subclass of typeddfs.matrix_dfs.AffinityMatrixDf.

Raises

Note

Copies, so this builder can be used to create more types without interference.

class typeddfs.builders.MatrixDfBuilder(name: str, doc: Optional[str] = None)

A builder pattern for typeddfs.matrix_dfs.MatrixDf.

Constructs a new builder.

Parameters
  • name – The name of the resulting class

  • doc – The docstring of the resulting class

Raises

TypeError – If name or doc non-string

_check_final(self) None
build(self) Type[typeddfs.matrix_dfs.MatrixDf]

Builds this type.

Returns

A newly created subclass of typeddfs.matrix_dfs.MatrixDf.

Raises
  • ClashError – If there is a contradiction in the specification

  • FormatInsecureError – If hash() set an insecure hash format and secure() was set.

Note

Copies, so this builder can be used to create more types without interference.

Raises

DfTypeConstructionError – for some errors

dtype(self, dt: Type[Any]) __qualname__

Sets the type of value for all matrix elements. This should almost certainly be a numeric type, and it must be ordered.

Returns

This builder for chaining

class typeddfs.builders.TypedDfBuilder(name: str, doc: Optional[str] = None)

A builder pattern for typeddfs.typed_dfs.TypedDf.

Example

TypedDfBuilder.typed().require("name").build()

Constructs a new builder.

Parameters
  • name – The name of the resulting class

  • doc – The docstring of the resulting class

Raises

TypeError – If name or doc non-string

_check(self, names: Sequence[str]) None
_check_final(self) None

Final method in the chain. Creates a new subclass of TypedDf.

Returns

The new class

Raises

typeddfs.df_errors.ClashError – If there is a contradiction in the specification

build(self) Type[typeddfs.typed_dfs.TypedDf]

Builds this type.

Returns

A newly created subclass of typeddfs.typed_dfs.TypedDf.

Raises

DfTypeConstructionError – If there is a contradiction in the specification

Note

Copies, so this builder can be used to create more types without interference.

drop(self, *names: str) __qualname__

Adds columns (and index names) that should be automatically dropped.

Parameters

names – Varargs list of names

Returns

This builder for chaining

require(self, *names: str, dtype: Optional[Type] = None, index: bool = False) __qualname__

Requires column(s) or index name(s). DataFrames will fail if they are missing any of these.

Parameters
  • names – A varargs list of columns or index names

  • dtype – An automatically applied transformation of the column values using .astype

  • index – If True, put these in the index

Returns

This builder for chaining

Raises

typeddfs.df_errors.ClashError – If a name was already added or is forbidden

reserve(self, *names: str, dtype: Optional[Type] = None, index: bool = False) __qualname__

Reserves column(s) or index name(s) for optional inclusion. A reserved column will be accepted even if strict is set. A reserved index will be accepted even if strict is set; additionally, it will be automatically moved from the list of columns to the list of index names.

Parameters
  • names – A varargs list of columns or index names

  • dtype – An automatically applied transformation of the column values using .astype

  • index – If True, put these in the index

Returns

This builder for chaining

Raises

typeddfs.df_errors.ClashError – If a name was already added or is forbidden

series_names(self, index: Union[None, bool, str] = False, columns: Union[None, bool, str] = False) __qualname__

Sets pd.DataFrame.index.name and/or pd.DataFrame.columns.name. Valid values are False to not set (default), None to set to None, or a string to set to.

Returns

This builder for chaining

strict(self, index: bool = True, cols: bool = True) __qualname__

Disallows any columns or index names not in the lists of reserved/required.

Parameters
  • index – Disallow additional names in the index

  • cols – Disallow additional columns

Returns

This builder for chaining