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
ordoc
non-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
name
ordoc
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 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
name
ordoc
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 ifstrict
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/orpd.DataFrame.columns.name
. Valid values areFalse
to not set (default),None
to 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