exceptions Module#

Custom exception classes for specific error conditions in epidemiological analysis.

This module defines a hierarchy of exceptions that provide precise error information for different failure modes.

Exception Hierarchy#

  • EpisiaError (base class) - ValidationError - ConvergenceError - ConfigurationError - DataError - ModelError - StatisticalError - DimensionError - ParameterError - ComputationError - FileError - PlotError

Classes#

class episia.core.exceptions.EpisiaError(message='An error occurred in Episia')[source]#

Bases: Exception

Base exception for all Episia errors.

Parameters:

message (str)

__init__(message='An error occurred in Episia')[source]#
Parameters:

message (str)

class episia.core.exceptions.ValidationError(message='Data validation failed')[source]#

Bases: EpisiaError

Raised when data validation fails.

Parameters:

message (str)

__init__(message='Data validation failed')[source]#
Parameters:

message (str)

class episia.core.exceptions.ConvergenceError(message='Algorithm failed to converge')[source]#

Bases: EpisiaError

Raised when numerical algorithm fails to converge.

Parameters:

message (str)

__init__(message='Algorithm failed to converge')[source]#
Parameters:

message (str)

class episia.core.exceptions.ConfigurationError(message='Invalid configuration')[source]#

Bases: EpisiaError

Raised when configuration is invalid.

Parameters:

message (str)

__init__(message='Invalid configuration')[source]#
Parameters:

message (str)

class episia.core.exceptions.DataError(message='Invalid or insufficient data')[source]#

Bases: EpisiaError

Raised when data is invalid or insufficient.

Parameters:

message (str)

__init__(message='Invalid or insufficient data')[source]#
Parameters:

message (str)

class episia.core.exceptions.ModelError(message='Model error occurred')[source]#

Bases: EpisiaError

Raised when model fitting or evaluation fails.

Parameters:

message (str)

__init__(message='Model error occurred')[source]#
Parameters:

message (str)

class episia.core.exceptions.StatisticalError(message='Statistical assumption violated')[source]#

Bases: EpisiaError

Raised when statistical assumptions are violated.

Parameters:

message (str)

__init__(message='Statistical assumption violated')[source]#
Parameters:

message (str)

class episia.core.exceptions.DimensionError(message='Dimension mismatch')[source]#

Bases: EpisiaError

Raised when array dimensions are incompatible.

Parameters:

message (str)

__init__(message='Dimension mismatch')[source]#
Parameters:

message (str)

class episia.core.exceptions.ParameterError(message='Invalid parameter value')[source]#

Bases: EpisiaError

Raised when function parameters are invalid.

Parameters:

message (str)

__init__(message='Invalid parameter value')[source]#
Parameters:

message (str)

class episia.core.exceptions.ComputationError(message='Numerical computation failed')[source]#

Bases: EpisiaError

Raised when numerical computation fails.

Parameters:

message (str)

__init__(message='Numerical computation failed')[source]#
Parameters:

message (str)

class episia.core.exceptions.FileError(message='File operation failed')[source]#

Bases: EpisiaError

Raised when file operations fail.

Parameters:

message (str)

__init__(message='File operation failed')[source]#
Parameters:

message (str)

class episia.core.exceptions.PlotError(message='Plotting failed')[source]#

Bases: EpisiaError

Raised when plotting fails.

Parameters:

message (str)

__init__(message='Plotting failed')[source]#
Parameters:

message (str)

class episia.core.exceptions.WarningManager[source]#

Bases: object

Manager for warnings in Episia.

Provides consistent warning formatting and filtering.

static filter_warnings(action='default')[source]#

Set warning filters for Episia.

Parameters:

action (str) – ‘default’, ‘ignore’, or ‘error’

Return type:

None

static warn(message, warning_type=<class 'UserWarning'>, stacklevel=2)[source]#

Issue a warning with consistent formatting.

Parameters:
  • message (str) – Warning message

  • warning_type (type) – Type of warning

  • stacklevel (int) – Stack level for warning origin

Return type:

None

Examples#

Using exceptions for error handling:

from episia.core.exceptions import ValidationError, WarningManager

try:
    # Some validation that might fail
    validate_2x2_table(-1, 10, 20, 30)
except ValidationError as e:
    print(f"Validation failed: {e}")

# Managing warnings
WarningManager.warn("This is a warning message")
WarningManager.filter_warnings("ignore")  # Suppress Episia warnings