pandas_dataclasses.core.api module#
- asframe(obj: DataClassOf[TFrame, PAny], *, factory: None = None) TFrame [source]#
- asframe(obj: DataClass[PAny], *, factory: Callable[[...], TFrame]) TFrame
- asframe(obj: DataClass[PAny], *, factory: None = None) DataFrame
Create a DataFrame object from a dataclass object.
The return type will be determined by a factory defined as the
__pandas_factory__
attribute in the original dataclass ofobj
or thefactory
argument. If neither is specified, it defaults topandas.DataFrame
.- Parameters:
obj – Dataclass object that should have attribute, column, data, and/or index fields. If the original dataclass has the
__pandas_factory__
attribute, it will be used as a factory for the DataFrame creation.- Keyword Arguments:
factory – Class or function for the DataFrame creation. It must take the same parameters as
pandas.DataFrame
, and return an object of it or its subclass. If passed, it will be preferentially used even if the original dataclass ofobj
has the__pandas_factory__
attribute.- Returns:
DataFrame object that complies with the original dataclass.
- aspandas(obj: DataClassOf[TPandas, PAny], *, factory: None = None) TPandas [source]#
- aspandas(obj: DataClass[PAny], *, factory: Callable[[...], TPandas]) TPandas
Create a DataFrame or Series object from a dataclass object.
Which data structure is created will be determined by a factory defined as the
__pandas_factory__
attribute in the original dataclass ofobj
or thefactory
argument. If a factory is a function, it must have an annotation of the return type.- Parameters:
obj – Dataclass object that should have attribute, column, data, and/or index fields. If the original dataclass has the
__pandas_factory__
attribute, it will be used as a factory for the data creation.- Keyword Arguments:
factory – Class or function for the DataFrame or Series creation. It must take the same parameters as
pandas.DataFrame
orpandas.Series
, and return an object of it or its subclass. If it is a function, it must have an annotation of the return type. If passed, it will be preferentially used even if the original dataclass ofobj
has the__pandas_factory__
attribute.- Returns:
DataFrame or Series object that complies with the original dataclass.
- Raises:
ValueError – Raised if no factory is found or the return type cannot be inferred from a factory when it is a function.
- asseries(obj: DataClassOf[TSeries, PAny], *, factory: None = None) TSeries [source]#
- asseries(obj: DataClass[PAny], *, factory: Callable[[...], TSeries]) TSeries
- asseries(obj: DataClass[PAny], *, factory: None = None) pd.Series[Any]
Create a Series object from a dataclass object.
The return type will be determined by a factory defined as the
__pandas_factory__
attribute in the original dataclass ofobj
or thefactory
argument. If neither is specified, it defaults topandas.Series
.- Parameters:
obj – Dataclass object that should have attribute, column, data, and/or index fields. If the original dataclass has the
__pandas_factory__
attribute, it will be used as a factory for the Series creation.- Keyword Arguments:
factory – Class or function for the Series creation. It must take the same parameters as
pandas.Series
, and return an object of it or its subclass. If passed, it will be preferentially used even if the original dataclass ofobj
has the__pandas_factory__
attribute.- Returns:
Series object that complies with the original dataclass.