skillfed

hampel

Python implementation of the Hampel Filter

hampel v1.0.2 228.5K downloads/30d#9,153 on PyPI67
Permissive license DORMANT released

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 hampel

uv

uv add hampel

poetry

poetry add hampel

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

time series outlier detectionhampel filter implementationanomaly detection sliding windowmedian absolute deviation filtertimeseries data cleaningoutlier removal pandasrobust statistical filtering
time-seriesoutlier-detectiondata-cleaning

More Information Analysis packages