Adapter API
Overview
The Adapter layer is a key component in the PETsARD architecture, responsible for wrapping each module into a unified execution interface for Executor invocation. Each Adapter provides standardized lifecycle methods and data flow management for its corresponding module.
Adapter Overall Architecture
classDiagram
class BaseAdapter {
<<abstract>>
+config: dict
+module_name: str
+__init__(config)
+run(input)
+set_input(status) dict
+get_result()
+get_metadata() Schema
}
class LoaderAdapter {
+loader: Loader
+benchmarker: Benchmarker
+run() tuple~DataFrame, Schema~
}
class SplitterAdapter {
+splitter: Splitter
+run() dict~str, DataFrame~
}
class PreprocessorAdapter {
+processor: Processor
+run() DataFrame
}
class SynthesizerAdapter {
+synthesizer: Synthesizer
+run() DataFrame
}
class PostprocessorAdapter {
+processor: Processor
+run() DataFrame
}
class ConstrainerAdapter {
+constrainer: Constrainer
+run() DataFrame
}
class EvaluatorAdapter {
+evaluator: Evaluator
+run() dict~str, DataFrame~
}
class DescriberAdapter {
+describer: Describer
+run() dict~str, DataFrame~
}
class ReporterAdapter {
+reporter: Reporter
+run() dict
}
BaseAdapter <|-- LoaderAdapter
BaseAdapter <|-- SplitterAdapter
BaseAdapter <|-- PreprocessorAdapter
BaseAdapter <|-- SynthesizerAdapter
BaseAdapter <|-- PostprocessorAdapter
BaseAdapter <|-- ConstrainerAdapter
BaseAdapter <|-- EvaluatorAdapter
BaseAdapter <|-- DescriberAdapter
BaseAdapter <|-- ReporterAdapter
%% Style definitions
style BaseAdapter fill:#F0F0F0
style LoaderAdapter fill:#E6E6FA
style SplitterAdapter fill:#E6E6FA
style PreprocessorAdapter fill:#E6E6FA
style SynthesizerAdapter fill:#E6E6FA
style PostprocessorAdapter fill:#E6E6FA
style ConstrainerAdapter fill:#E6E6FA
style EvaluatorAdapter fill:#E6E6FA
style DescriberAdapter fill:#E6E6FA
style ReporterAdapter fill:#E6E6FALegend:
- Gray box: Abstract base class
- Light purple box: Concrete Adapter implementation classes
<|--: Inheritance relationship
Architecture
All Adapter classes inherit from BaseAdapter and implement the following core interface:
Core Methods
__init__(config: dict)- Initialize adapter with configurationrun(input: dict)- Execute the module’s functionality with timingset_input(status)- Prepare input data from Status objectget_result()- Retrieve execution resultsget_metadata()- Retrieve metadata (Schema) if applicable
Utility Methods
BaseAdapter provides several utility methods for common operations:
_apply_precision_rounding()- Apply precision rounding to numerical columns based on schema_update_schema_stats()- Recalculate statistics and update schema_handle_benchmark_download()- Handle benchmark:// protocol downloads_resolve_data_source()- Unified data source resolution supporting “Module.key” format_get_metadata_with_priority()- Retrieve metadata with priority order_safe_copy()- Unified copy strategy based on data type
Adapter Classes
| Adapter | Corresponding Module | Key Features |
|---|---|---|
LoaderAdapter | Loader | Data loading with benchmark:// protocol support |
SplitterAdapter | Splitter | Data splitting with custom_data method support |
PreprocessorAdapter | Processor | Preprocessing with global outlier config expansion |
SynthesizerAdapter | Synthesizer | Data synthesis with custom_data method support |
PostprocessorAdapter | Processor | Postprocessing with dtype restoration |
ConstrainerAdapter | Constrainer | Constraint application with resample/validate modes |
EvaluatorAdapter | Evaluator | Evaluation with auto dtype alignment |
DescriberAdapter | Describer | Descriptive statistics with describe/compare modes |
ReporterAdapter | Reporter | Report generation with timing and validation support |
Basic Usage Pattern
from petsard.adapter import LoaderAdapter
# Create adapter
adapter = LoaderAdapter(config)
# Set input from Status
input_data = adapter.set_input(status)
# Execute with timing
adapter.run(input_data)
# Get results
result = adapter.get_result()
metadata = adapter.get_metadata() # If applicableError Handling
All Adapters use decorator pattern for error handling:
@log_and_raise_config_error- Configuration error handling with detailed logging@log_and_raise_not_implemented- Not implemented method handling
Data Flow
Adapters manage data flow between modules through the Status object:
- Input Phase:
set_input()retrieves data from previous modules via Status - Execution Phase:
run()executes the wrapped module with timing - Output Phase:
get_result()andget_metadata()provide results to Status
Important Notes
- Adapter layer is internal architecture - direct use is not recommended
- Prefer using YAML configuration files with
Executor - All data modifications respect Schema precision and statistics settings
- Benchmark downloads are handled transparently via benchmark:// protocol
- See individual Adapter pages for detailed configuration options