Add opt-in winsorization for revenue/price outliers - #34
Merged
Conversation
Business reports (Average Order Value, revenue trend, category revenue breakdown) all read from the same price/revenue column, so a handful of extreme values (e.g. one bulk order) can dilute those stats without any way to address it short of manually editing the source data. Adds prox.winsorize_series() - same technique as first-order-engine's ContinuousMetricEngine.winsorize_series (mean +/- N std devs, or a percentile band), adapted to return a Series instead of a JSON list to match this codebase's DataFrame-in/DataFrame-out convention. Wired into main.py as a new opt-in "2. Handle Outliers" step, applied to both raw_df and df_ready right after the data is loaded and cached, before any filtering/sampling/analysis reads the price column - capping values rather than dropping the rows they came from.
BasLinders
force-pushed
the
winsorize-revenue-outliers
branch
from
August 21, 2026 11:55
174b8c5 to
7545b7c
Compare
BasLinders
marked this pull request as ready for review
August 21, 2026 11:57
BasLinders
added a commit
that referenced
this pull request
Sep 8, 2026
Add opt-in winsorization for revenue/price outliers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prox.winsorize_series()inprox/data_manager.py: same technique as first-order-engine'sContinuousMetricEngine.winsorize_series(https://github.com/BasLinders/first-order-engine/blob/main/foe/continuous/operations.py#L110) — caps values at mean ± N standard deviations, or at a percentile band — adapted to return apd.Seriesinstead of a JSON-serializable list, to match this codebase's DataFrame-in/DataFrame-out convention (PRoX doesn't depend onfoeoutside the optional BigQuery extra, so this isn't imported from there).main.pyas a new opt-in "2. Handle Outliers" step (existing sections renumbered 3→6 to make room), applied to the revenue/price column on bothraw_dfanddf_readyright after the data is loaded/cached and before any filtering, sampling, or analysis reads that column — caps values in place rather than dropping the rows they came from.Why
Average Order Value, revenue trend, and category revenue breakdown in Business Insights all read from the same price/revenue column, so a handful of extreme values (e.g. one bulk order) can dilute those stats with no way to address it short of editing the source data. Scoped to the revenue/price column specifically — winsorizing case duration/lead time directly would mean mutating event timestamps, which is a separate, more invasive change.
Test plan
pytest tests/— 135 passed (6 new tests: percentile capping of a single injected outlier, std-based bounds matchmean ± N·std, NaN positions preserved, no-outlier case leaves values unchanged, empty/all-NaN series return zero bounds)first-order-engineimplementation, not a regression)pricefed intorun_full_analysisand confirmed Average Order Value reflects the capped values