ToleranceDeviationEvents
Samples of a measurement outside its specification limits, grouped into events with deviation size and severity, and the capability indices Cp, Cpk, Pp, Ppk and Cpm. The limits are signals in the same frame, so they can change over time.
ts_shape.events.quality.tolerance_deviation · Quality guide · API reference
Example
import pandas as pd
import ts_shape
from ts_shape.events.quality.tolerance_deviation import ToleranceDeviationEvents
df = pd.concat([
ts_shape.make_timeseries(["shaft_diameter"], n_points=500, baseline=50.0, noise=0.3, n_outliers=4),
ts_shape.make_timeseries(["shaft_diameter:usl"], n_points=1, baseline=51.0, noise=0),
ts_shape.make_timeseries(["shaft_diameter:lsl"], n_points=1, baseline=49.0, noise=0),
], ignore_index=True)
tdev = ToleranceDeviationEvents(df, value_column_tolerance="value_double", value_column_actual="value_double",
actual_uuid="shaft_diameter", upper_tolerance_uuid="shaft_diameter:usl",
lower_tolerance_uuid="shaft_diameter:lsl", event_uuid="quality:tolerance")
print(tdev.detect_deviations()[["systime", "value_double", "deviation_abs", "severity"]])
capability = tdev.capability_indices(target_value=50.0)
Methods
| Method | Returns |
|---|---|
detect_deviations() | out-of-tolerance events: systime, the measured value, deviation_abs, deviation_pct, severity (minor/major/critical) |
capability_indices(target_value=None, sigma_method='moving_range') | one row: cp, cpk, pp, ppk, cpm (each after its deprecated upper-case twin), mean, std, std_within, usl, lsl, target, sample_count |
Formulas
With (within) and the overall sample standard deviation:
Notes
- Each sample is checked against the latest limit values at that time. Every row of a limit signal sets the limit, whatever its
is_deltaflag (snapshot limits are valid; the column is not needed).tolerance_lagshifts the limit timestamps: a limit set atttakes effect att + tolerance_lag, and events keep the measured times. Out-of-tolerance samples closer thantime_threshold(default5min) form one event, reported as its first and last row; a single-sample event is one row. - Severity is by the distance beyond the violated limit (
deviation_abs), relative to the tolerance range R (upper − lower; the single limit's magnitude when one-sided):minorwhendeviation_abs ≤ warning_threshold × R(default 0.8),criticalwhendeviation_abs > 2 × R,majorin between. With limits [0, 10], a value of 11 isminor, 19major, 31critical. - Two-sided spec: pass both
upper_tolerance_uuidandlower_tolerance_uuid. With only one the spec is one-sided: Cp/Pp are NaN, Cpk/Ppk are CPU or CPL, anddeviation_pctis relative to the single limit. - Cp/Cpk use the within σ̂ = MR̄ / 1.128 of consecutive measurements (
std_within); Pp/Ppk use the overall sample standard deviation (std), as in the AIAG SPC manual.sigma_method="std"computes Cp/Cpk from the overall σ (Cp = Pp, the behavior before October 2026).Cpm = (USL − LSL) / (6·sqrt(σ² + (mean − target)²))with the overall σ is computed only withtarget_value; otherwisetargetreports the spec midpoint. actual_uuidis required. The singletolerance_uuid(compared throughcompare_func) is deprecated; a single upper limit isupper_tolerance_uuidalone.capability_indices(..., as_frame=False)returns the deprecated dict.- Measurements without spread (constant values, a single measurement or only missing values) give NaN capability indices and a
DataQualityWarning, as inCapabilityTrendingEvents. Without rows of the actual signal,capability_indices()returns the empty frame and aDataQualityWarning.