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
nameordocnon-string
- build(self) Type[typeddfs.matrix_dfs.AffinityMatrixDf]ο
Builds this type.
- Returns
A newly created subclass of
typeddfs.matrix_dfs.AffinityMatrixDf.- Raises
typeddfs.df_errors.ClashError β If there is a contradiction in the specification
typeddfs.df_errors.FormatInsecureError β If
hash()set an insecure hash format andsecure()was set.
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
nameordocnon-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 andsecure()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
nameordocnon-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
.astypeindex β 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
strictis set. A reserved index will be accepted even ifstrictis 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
.astypeindex β 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.nameand/orpd.DataFrame.columns.name. Valid values areFalseto not set (default),Noneto set toNone, 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