xplainable-preprocessing
Shared preprocessing pipeline library for xplainable. Define, compile, fit, serialise, and apply data transformation pipelines using a declarative JSON spec.
Install
pip install xplainable-preprocessing
pip install "xplainable-preprocessing[excel]" # io.read_table for .xlsx/.xls
Upgrading from 0.3.x? 0.4.0 has breaking changes; see CHANGELOG.md.
Quick Start
Define a pipeline as JSON
from xplainable_preprocessing.schema import PipelineSpec
from xplainable_preprocessing.compiler import compile_spec
spec = PipelineSpec(
version="2.0",
steps=[
{"id": "drop_ids", "type": "DropColumnsTransformer", "params": {"columns": ["customer_id", "row_id"]}},
{"id": "fill_numeric", "type": "FillMissingTransformer", "columns": ["tenure", "charges"], "params": {"strategies": {"tenure": "median", "charges": "median"}}},
{"id": "clip_outliers", "type": "ClipTransformer", "columns": ["charges"], "params": {"min_val": 0, "max_val": 500}},
{"id": "missing_flags", "type": "MissingFlagTransformer", "columns": ["tenure", "charges"]},
{"id": "condense_plan", "type": "CategoryCondenseTransformer", "columns": ["plan_type"], "params": {"max_categories": 10}},
{"id": "extract_dates", "type": "DateTimeExtractTransformer", "columns": ["signup_date"], "params": {"components": ["month", "dayofweek"], "drop_original": true}},
]
)
pipeline = compile_spec(spec)
Fit and transform
import pandas as pd
df = pd.read_csv("data.csv")
pipeline.fit(df)
transformed = pipeline.transform(df)
Serialise and load
from xplainable_preprocessing.serialization import save_pipeline, load_pipeline
# Save
binary = save_pipeline(pipeline)
# Load
loaded = load_pipeline(binary)
result = loaded.transform(new_data)
Available Transformers
Data Cleaning
| Transformer | Description |
|---|---|
DropColumnsTransformer |
Drop specified columns |
RenameColumnsTransformer |
Rename columns |
TypeCastTransformer |
Cast column dtypes (e.g. str to float64, with error coercion) |
ClipTransformer |
Set numeric values outside (min, max), or per-column bounds, to NaN |
ParseNumericTransformer |
Parse numbers stored as text (%, currency, 1,234, 36 months, ranges, 10+) |
NullTokensTransformer |
Turn placeholder text (?, N/A) and sentinel numbers (999) into NaN |
Missing Values
| Transformer | Description |
|---|---|
FillMissingTransformer |
Fill nulls with median, mode, constant, or other strategies |
MissingFlagTransformer |
Create binary 0/1 indicator columns for nulls |
Feature Engineering
| Transformer | Description |
|---|---|
ExpressionTransformer |
Create derived columns from expressions (allow-listed evaluator) |
DateTimeExtractTransformer |
Extract year, month, dayofweek, elapsed time, etc. from datetime columns |
GroupByAggTransformer |
Aggregate features by group (count, sum, mean) |
GroupedLagTransformer |
Create row-shift lags within groups |
RollingAggTransformer |
Rolling window aggregations |
TimeLagTransformer |
Lags and trailing windows at exact time offsets over strictly earlier rows |
GroupBroadcastTransformer |
Write a group aggregate (e.g. a holiday flag per date) to every row of the group |
TextFeaturesTransformer |
Numeric features from free text (length, digits, URLs, keyword flags) |
Categorical
| Transformer | Description |
|---|---|
CategoryCondenseTransformer |
Condense high-cardinality categoricals to top N + "Other" |
TextCleanTransformer |
Clean text cells: lowercase, strip, remove HTML/extra whitespace, fix encoding, mask digits/URLs/emails |
OrdinalMapTransformer |
Map an ordered scale (grades, ratings, bands) to numbers |
CrossCategoriesTransformer |
Cross 2-3 low-cardinality columns into one category |
Scaling (use with caution -- breaks xplainable model explainability)
| Transformer | Description |
|---|---|
StandardScaler |
Standardise to zero mean, unit variance |
MinMaxScaler |
Scale to [0, 1] range |
RobustScaler |
Scale using median and IQR |
PowerTransformer |
Apply power transform for normality |
QuantileTransformer |
Transform to uniform or normal distribution |
Note: Scaling transformers are available but should NOT be used with xplainable models. xplainable models are inherently explainable and require raw feature values. Scaling destroys interpretability.
Other sklearn
| Transformer | Description |
|---|---|
SimpleImputer |
sklearn's imputer |
OneHotEncoder |
One-hot encode categoricals |
OrdinalEncoder |
Ordinal encode categoricals |
KBinsDiscretizer |
Discretise continuous features into bins |
Binarizer |
Threshold features to binary |
Pipeline Spec Format
Pipelines are defined as JSON for portability across the xplainable platform, MCP tools, and API:
{
"version": "2.0",
"steps": [
{
"id": "step_name",
"type": "TransformerName",
"columns": ["col1", "col2"],
"params": {"param1": "value1"},
"description": "Optional description"
}
]
}
id: unique step identifiertype: transformer class name (from the registry)columns: optional list of columns to apply to (wraps inDataFrameColumnTransformer)params: constructor arguments for the transformerdescription: optional human-readable description
Architecture
PipelineSpec (JSON)
↓ compile_spec()
DataFramePipeline (sklearn Pipeline of transformers)
↓ fit() / transform()
Transformed DataFrame
↓ save_pipeline()
Binary (cloudpickle)
↓ load_pipeline()
DataFramePipeline (restored)
Key modules:
schema.py-- Pydantic models forPipelineSpecandStepSpeccompiler.py-- compiles JSON spec into sklearn pipelinepipeline.py--DataFramePipelinewrapper around sklearnPipelineregistry.py-- maps transformer names to classes, generates LLM-ready catalogserialization.py-- cloudpickle save/load; portable across Python versionsguard.py-- step safety checks and step/spec previewspreview.py-- before/after preview with schema deltascontracts.py-- which engineered columns each step computes (dependency_map,partial_transform)detect/-- detectors that describe a raw frame (scan_all,Issue)io.py--read_table, the shared CSV/Excel readernumeric_text.py-- parse numbers stored as text
Development
pip install -e ".[dev]"
pytest
License
MIT
Metadata
Release files for xplainable-preprocessing 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xplainable_preprocessing-0.4.0.tar.gz | 638.8 kB | Without provenance | Details for xplainable_preprocessing-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xplainable_preprocessing-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for xplainable_preprocessing-0.4.0-py3-none-any.whl |
Total release size: 835.5 kB
Release files / xplainable_preprocessing-0.4.0.tar.gz
| Download URL | xplainable_preprocessing-0.4.0.tar.gz |
|---|---|
| Size | 638.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
519630e88518b0a72ab55a7e3fa57957a955eac9b173cc6555c20e18628bf7e9
|
|
BLAKE2b-256 checksum How to use checksums |
6e535c878326d2202279192157c70ef582ffc5fa8318ed3422bed7741a372e4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / xplainable_preprocessing-0.4.0-py3-none-any.whl
| Download URL | xplainable_preprocessing-0.4.0-py3-none-any.whl |
|---|---|
| Size | 196.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fc8fb37e8e61c3923efe618dada2064085ddf45973beebfaa10705c7418070a
|
|
BLAKE2b-256 checksum How to use checksums |
7fd81b56299b66705845005e2257b9be3257cd4ff9dc2bc007028c2a1f249c7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for xplainable-preprocessing 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.