base
base
Base models and shared functionality.
Classes
Base
Bases: BaseModel
Custom base model that
- Collects non-breaking validation or runtime warnings using WarningCollector
- Fails fast on critical errors
- Catches validation errors and converts them into warnings
- Validates on assignment, converting assignment errors into warnings
- Provides serialization to DataFrame
Initialize the model, converting validation errors to warnings.
Source code in src/pyetm/models/base.py
Attributes
Functions
__setattr__
Handle assignment with validation error capture.
Source code in src/pyetm/models/base.py
add_warning
Add a warning to this model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Field name where warning occurred |
required |
message
|
Union[str, List[str], Dict[str, Any]]
|
Warning message (str, list of strings, or dict) |
required |
severity
|
Literal['info', 'warning', 'error']
|
Warning severity level (info/warning/error) |
'warning'
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If error policy determines warning should raise an exception |
Source code in src/pyetm/models/base.py
set_bulk_context
Set whether this model is being processed in a bulk operation context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_bulk
|
bool
|
True if in bulk operation, False for single operation |
True
|
Note
This affects error handling behavior. In bulk operations, errors are collected as warnings to allow partial success. In single operations, errors may raise exceptions based on the error_mode setting.
Source code in src/pyetm/models/base.py
show_warnings
auto_show_warnings
Automatically display warnings if any exist, with contextual information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
str
|
Additional context to display (e.g., "SavedScenario #123") |
''
|
Source code in src/pyetm/models/base.py
log_warnings
Log all collected warnings using the provided logger.
Source code in src/pyetm/models/base.py
from_dataframe
classmethod
Create an instance from a pandas DataFrame.
Source code in src/pyetm/models/base.py
to_dataframe
Public method that handles common serialization logic and delegates to _to_dataframe().
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Serialized DataFrame with class name as index level |