hampel
Python implementation of the Hampel Filter
What it is and what it does
Hampel is a Python implementation of the Hampel filter, a statistical method for detecting and removing outliers in time-series data. It uses a sliding window approach, computing the Median Absolute Deviation (MAD) for each window and flagging observations that deviate from the median by more than a configurable threshold (n_sigma). Outliers are then replaced with the window's median value.
The package works with pandas Series and numpy arrays, and returns a Result object containing the filtered data, outlier indices, medians, MAD values, and thresholds. It is designed for cleaning noisy time-series before analysis or modeling, and integrates naturally with pandas workflows via the apply method on DataFrames.
Use it for:
- Clean sensor or measurement data before feeding it to a machine learning model.
- Detect and remove spikes in financial time-series (stock prices, trading volumes).
- Preprocess IoT or monitoring data to identify equipment anomalies or sensor faults.
- Prepare time-series datasets for statistical analysis or forecasting by removing outliers.
- Identify and flag unusual events in log or event-stream data for further investigation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Hampel detects and filters outliers in time-series data by comparing each observation against the Median Absolute Deviation within a sliding window, replacing anomalies with median values.
Yes, if you need robust outlier detection for time-series data and can tolerate dormant maintenance. The package is stable, has no known vulnerabilities, and MIT licensing poses no risk. However, verify that breaking changes in version 1.0.1 do not affect your use case, and be aware that numpy and pandas are substantial dependencies. Not recommended if you need active maintenance or frequent updates.
Install
hampel on PyPI
pip
pip install hampeluv
uv add hampelpoetry
poetry add hampelInstalling hampel
Before you install
High install friction: the package depends on numpy and pandas, which are substantial dependencies. Maintenance is dormant—last release was 1060 days ago (2023-09-19), with the last commit in 2024-02-06. Breaking changes were introduced in version 1.0.1, so upgrading requires code review.
License in practice
Licensed under MIT (permissive), so you can use it freely in commercial and private projects with minimal restrictions.
Quickstart
pip install hampel
import pandas as pd
from hampel import hampel
data = pd.Series([1.0, 2.0, 3.0, 100.0, 4.0, 5.0, 6.0])
result = hampel(data, window_size=3, n_sigma=3.0)
print(result.filtered_data)
Requires Python >= 3.8 and numpy and pandas as runtime dependencies.
Verify before relying
- Whether breaking changes in version 1.0.1 affect common use patterns or are edge-case only.
- Performance characteristics on large datasets or high-dimensional data.
- Whether the dormant maintenance status indicates the library is stable or at risk of incompatibility with future pandas/numpy versions.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | high — source build required |
| Runtime dependencies | 2 — numpy, pandas |
| Maintenance | dormant — 1,060 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 228,454/month — #9,153 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: hampel-1.0.2.tar.gz
Tags
More Information Analysis packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyarrowpyarrow provides Python bindings to Apache…
permissive · top 100 on PyPI
networkxNetworkX provides data structures and…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
snowflake-snowpark-pythonSnowpark Python provides APIs to query and…
permissive · top 1,000 on PyPI
u8dartsu8darts is a deprecated compatibility shim that…
permissive · top 15,000 on PyPI
dartsDarts provides forecasting and anomaly…
permissive · top 15,000 on PyPI
pyodPyOD detects anomalies and outliers across…
permissive · top 5,000 on PyPI
alibi-detectAlibi Detect provides outlier, adversarial, and…
unclear · top 15,000 on PyPI
stockstatsAdds technical analysis indicators and…
permissive · top 15,000 on PyPI
datasieveDataSieve extends scikit-learn's Pipeline to…
permissive · top 15,000 on PyPI
adtkADTK provides detectors, transformers, and…
copyleft · top 15,000 on PyPI
prophetProphet forecasts time series data using an…
permissive · top 5,000 on PyPI
semhashSemHash deduplicates, filters outliers from,…
permissive · top 15,000 on PyPI
anomaloProvides a Python client library and…
permissive · top 15,000 on PyPI