mutcleaner.core.pipeline#
Functions
|
Create a new pipeline with initial data |
|
Decorator factory for multi-output pipeline functions. |
|
Classes
|
Pipeline for processing data with pandas-style method chaining |
- class mutcleaner.core.pipeline.Pipeline(data=None, name=None, logging_level='INFO')[source]#
Bases:
objectPipeline for processing data with pandas-style method chaining
- Attributes:
artifactsAlways return the artifacts dictionary.
dataAlways return the actual data, never PipelineOutput.
has_pending_stepsCheck if there are delayed steps waiting to be executed
structured_dataReturn PipelineOutput object with both data and artifacts.
Methods
add_delayed_step(func[, index])Add a delayed step before a specific position in the delayed execution queue.
apply(func, *args, **kwargs)Apply function and return new Pipeline (functional style)
assign(**kwargs)Add attributes or computed values to data
copy()Create a deep copy of this pipeline
delayed_then(func, *args, **kwargs)Add a function to the delayed execution queue without running it immediately
execute([steps])Execute delayed steps.
filter(condition)Filter data based on condition
Get all stored artifacts
get_artifact(name)Get a specific artifact by name
get_data()Get current data (same as .data property).
Get information about delayed steps
Get summary of pipeline execution
get_step_result(step_index)Get result from a specific step by index or name
load(filepath[, format, name])Load data from file and create new pipeline
load_structured_data(filepath[, format, name])Load structured data from file and create new pipeline
peek([func, prefix])Inspect data without modifying it (for debugging)
remove_delayed_step(index_or_name)Remove a delayed step at the specified index.
save(filepath[, format])Save current data to file
save_artifacts(filepath[, format])Save all artifacts to file
save_structured_data(filepath[, format])Save structured data (data + artifacts) to file
store(name[, extractor])Store current data or extracted value as artifact
then(func, *args, **kwargs)Apply a function to the current data (pandas.pipe style)
transform(transformer, *args, **kwargs)Alias of then, used to define format transformations.
validate(validator[, error_msg])Validate data and raise error if invalid
Generate a text visualization of the pipeline
- add_delayed_step(func, index=None, *args, **kwargs)[source]#
Add a delayed step before a specific position in the delayed execution queue.
Performs a similar action to the list.insert() method.
- Parameters:
func (
Callable) – Function to add as delayed stepindex (
Optional[int]) – Position to insert the step. If None, appends to the end. Supports negative indexing.**kwargs (*args,) –
Arguments to pass to the function
- Return type:
- Returns:
Self for method chaining
Examples
>>> # Add step at the beginning >>> pipeline.add_delayed_step(func1, 0)
>>> # Add step at the end (same as delayed_then) >>> pipeline.add_delayed_step(func2)
>>> # Insert step at position 2 >>> pipeline.add_delayed_step(func3, 2)
>>> # Insert step before the last one >>> pipeline.add_delayed_step(func4, -1)
- apply(func, *args, **kwargs)[source]#
Apply function and return new Pipeline (functional style)
- Return type:
- property artifacts: Dict[str, Any]#
Always return the artifacts dictionary.
This provides direct access to all stored artifacts from pipeline steps.
- property data: Any#
Always return the actual data, never PipelineOutput.
This ensures consistent user experience - pipeline.data can always be used with methods like .copy(), .append(), etc.
- delayed_then(func, *args, **kwargs)[source]#
Add a function to the delayed execution queue without running it immediately
- Return type:
- execute(steps=None)[source]#
Execute delayed steps.
- Parameters:
steps (
Union[int,List[int],None]) – Which delayed steps to execute: - None: execute all delayed steps - int: execute the first N delayed steps - List[int]: execute specific delayed steps by index- Return type:
- Returns:
Self for method chaining
- get_data()[source]#
Get current data (same as .data property).
Kept for backward compatibility.
- Return type:
Any
- get_delayed_steps_info()[source]#
Get information about delayed steps
- Return type:
List[Dict[str,Any]]
- get_step_result(step_index)[source]#
Get result from a specific step by index or name
- Return type:
Any
- property has_pending_steps: bool#
Check if there are delayed steps waiting to be executed
- classmethod load(filepath, format='pickle', name=None)[source]#
Load data from file and create new pipeline
- Return type:
- classmethod load_structured_data(filepath, format='pickle', name=None)[source]#
Load structured data from file and create new pipeline
- Return type:
- remove_delayed_step(index_or_name)[source]#
Remove a delayed step at the specified index.
- Parameters:
index (int) – Index of the delayed step to remove
- Return type:
- Returns:
Self for method chaining
- Raises:
ValueError – If no delayed step is found with the specified index or name
- save_structured_data(filepath, format='pickle')[source]#
Save structured data (data + artifacts) to file
- Return type:
- property structured_data: PipelineOutput#
Return PipelineOutput object with both data and artifacts.
Use this when you need the complete pipeline state for serialization, passing to other systems, or when working with structured data flows.
- then(func, *args, **kwargs)[source]#
Apply a function to the current data (pandas.pipe style)
- Return type:
- transform(transformer, *args, **kwargs)[source]#
Alias of then, used to define format transformations.
- Return type:
- mutcleaner.core.pipeline.create_pipeline(data, name=None, **kwargs)[source]#
Create a new pipeline with initial data
- Return type:
- mutcleaner.core.pipeline.multiout_step(**outputs)[source]#
Decorator factory for multi-output pipeline functions.
- Parameters:
**outputs (
str) – Named outputs. Use ‘main’ to specify which output is the main data flow. If ‘main’ is not specified, the first return value is treated as main.- Return type:
Callable[[Callable[[ParamSpec(P, bound=None)],Union[Tuple[Any,...],Any]]],Callable[[ParamSpec(P, bound=None)],MultiOutput]]
Examples
>>> @multiout_step(stats="statistics", plot="visualization") ... def analyze_data(data): ... # return (main, stats, plot) ... return processed, stats_dict, plot_obj
- mutcleaner.core.pipeline.pipeline_step(_func=None, *, name=None)[source]#
- Overloads:
_func (Callable[P, R]) → Callable[P, R]
name (Optional[str]) → Callable[[Callable[P, R]], Callable[P, R]]
Decorator for single-output pipeline functions.
Use this for functions that return a single value (including tuples as single values). For multiple outputs, use @multiout_step instead.
- Parameters:
name (
Optional[str]) – Custom name for the step. If None, uses function name.
Examples
>>> @pipeline_step ... def process(data): ... return processed_data # Single output
>>> @pipeline_step("process_data") ... def process(data): ... return processed_data # Single output
>>> @pipeline_step() ... def get_coordinates(): ... return (10, 20) # Single tuple output