pyprobe.result module#
A module for the Result class.
- pydantic model Result(*, base_dataframe, info, column_definitions=None)#
Bases:
BaseModel
A class for holding any data in PyProBE.
A Result object is the base type for every data object in PyProBE. This class includes all of the main methods for returning and describing any data in PyProBE.
- Key attributes for returning data:
- Key attributes for describing the data:
info
: A dictionary containing information about the cell.column_definitions
: A dictionary of column definitions.print_definitions()
: Print the column definitions.column_list
: A list of column names.
- Validators:
_load_base_dataframe
»all fields
- Parameters:
base_dataframe (LazyFrame | DataFrame)
info (Dict[str, str | int | float | Dict[Any, Any] | None])
column_definitions (Dict[str, str])
- Return type:
None
- field base_dataframe: LazyFrame | DataFrame [Required]#
The data as a polars DataFrame or LazyFrame.
- Validated by:
_load_base_dataframe
- field info: Dict[str, str | int | float | Dict[Any, Any] | None] [Required]#
Dictionary containing information about the cell.
- Validated by:
_load_base_dataframe
- field column_definitions: Dict[str, str] [Optional]#
A dictionary containing the definitions of the columns in the data.
- Validated by:
_load_base_dataframe
- property data: DataFrame#
Return the data as a polars DataFrame.
- Returns:
The data as a polars DataFrame.
- Return type:
pl.DataFrame
- Raises:
ValueError – If no data exists for this filter.
- property contains_lazyframe: bool#
Return whether the data is a LazyFrame.
- Returns:
True if the data is a LazyFrame, False otherwise.
- Return type:
bool
- get(*column_names)#
Return one or more columns of the data as seperate 1D numpy arrays.
- Parameters:
column_names (str) – The column name(s) to return.
- Returns:
The column(s) as numpy array(s).
- Return type:
Union[NDArray[np.float64], Tuple[NDArray[np.float64], …]]
- Raises:
ValueError – If no column names are provided.
ValueError – If a column name is not in the data.
- get_only(column_name)#
Return a single column of the data as a numpy array.
- Parameters:
column_name (str) – The column name to return.
- Returns:
The column as a numpy array.
- Return type:
NDArray[np.float64]
- Raises:
ValueError – If the column name is not in the data.
ValueError – If no column name is provided.
- array(*filtering_column_names)#
Return the data as a single numpy array.
- Parameters:
*filtering_column_names (str) – The column names to return.
- Returns:
The data as a single numpy array.
- Return type:
NDArray[np.float64]
- Raises:
ValueError – If a column name is not in the data.
- property quantities: List[str]#
The quantities of the data, with unit information removed.
- Returns:
The quantities of the data.
- Return type:
List[str]
- property column_list: List[str]#
The columns in the data.
- Returns:
The columns in the data.
- Return type:
List[str]
- define_column(column_name, definition)#
Define a new column when it is added to the dataframe.
- Parameters:
column_name (str) – The name of the column.
definition (str) – The definition of the quantity stored in the column
- Return type:
None
- print_definitions()#
Print the definitions of the columns stored in this result object.
- Return type:
None
- clean_copy(dataframe=None, column_definitions=None)#
Create a copy of the result object with info dictionary but without data.
- Parameters:
dataframe (Optional[Union[pl.DataFrame, pl.LazyFrame]) – The data to include in the new Result object.
column_definitions (Optional[Dict[str, str]]) – The definitions of the columns in the new result object.
- Returns:
A new result object with the specified data.
- Return type:
- add_new_data_columns(new_data, date_column_name)#
Add new data columns to the result object.
The data must be time series data with a date column. The new data is joined to the base dataframe on the date column, and the new data columns are interpolated to fill in missing values.
- Parameters:
new_data (pl.DataFrame | pl.LazyFrame) – The new data to add to the result object.
date_column_name (str) – The name of the column in the new data containing the date.
- Raises:
ValueError – If the base dataframe has no date column.
- Return type:
None
- join(other, on, how='inner', coalesce=True)#
Join two Result objects on a column. A wrapper around the polars join method.
This will extend the data in the Result object horizontally. The column definitions of the two Result objects are combined, if there are any conflicts the column definitions of the calling Result object will take precedence.
- Parameters:
other (Result) – The other Result object to join with.
on (Union[str, List[str]]) – The column(s) to join on.
how (str) – The type of join to perform. Default is ‘inner’.
coalesce (bool) – Whether to coalesce the columns. Default is True.
- Return type:
None
- extend(other, concat_method='diagonal')#
Extend the data in this Result object with the data in another Result object.
This method will concatenate the data in the two Result objects, with the Result object calling the method above the other Result object. The column definitions of the two Result objects are combined, if there are any conflicts the column definitions of the calling Result object will take precedence.
- classmethod build(data_list, info)#
Build a Result object from a list of dataframes.
- Parameters:
data_list (List[List[pl.LazyFrame | pl.DataFrame | Dict]]) – The data to include in the new result object. The first index indicates the cycle and the second index indicates the step.
info (Dict[str, Optional[str | int | float]]) – A dict containing test info.
- Returns:
A new result object with the specified data.
- Return type: