Repository navigation
Adjust quartile and generated bins to special outliers - #12472
Tanishq-Choudhary wants to merge 3 commits into
Conversation
Quartile and generated bins were built from every numeric value and never trimmed to the bounds of special outlier values such as "<=40" or ">52". Values inside those bounds were counted in the outlier bin and in the first or last data bin, and when a whole bin fell inside the bound, moving its edge to the bound threw "Invalid range". Apply adjustCustomBins to them as custom bins already do, and use a single remaining boundary as the outlier split for all three methods. adjustCustomBins also no longer adds a bound that is already one of the bins, which made a zero-width bin and counted its values twice.
arieleven
left a comment
There was a problem hiding this comment.
Nice fix. Running generated and quartile boundaries through adjustCustomBins closes the case where the first bin started below a special lower outlier and later got its start moved past its end. The noneMatch guard also stops a duplicate boundary (and so a zero-width bin) when the special value lands exactly on a bin edge. The three tests read clearly and line up with the counts I worked out by hand.
One edge case I think the new single-boundary branch doesn't reach for quartiles. If the special outlier sits exactly on Q3 (say the data has <=73 and Q3 is 73), adjustCustomBins([Q1, Q2, 73]) keeps only [73], because 73 is already in the list and isn't added back. One boundary gives zero linear bins, so this branch fires first:
if (MEDIAN == binMethod || (QUARTILE == binMethod && dataBins.size() == 0)) {
lowerOutlierBin.setEnd(median);
upperOutlierBin.setStart(median);
} else if (adjustedBins != null && adjustedBins.size() == 1) { ... }The outlier bins would then split at the median (<=55 / >55 in the 20..90 data from your quartile test) and not at 73, so the values the dataset reports as <=73 end up counted under a <=55 label. Checking adjustedBins.size() == 1 before the quartile-empty fallback, or limiting that fallback to the case where adjustedBins is empty or all quartiles were identical, would keep the special value as the split point. A variant of testLinearDataBinnerQuartileBinsWithSpecialOutlierAboveQ1 with <=73 would cover it.
Small thing: adjustCustomBins is now used for all three methods, so a more neutral name (e.g. adjustBinsToOutliers) and a Javadoc that mentions generated and quartile bins would help the next reader.
When a special outlier value equals Q3, the adjusted quartile bins reduce to that one value, which gives no linear bins. The quartile fallback to the median ran first, so values counted as "<=35" ended up under a "<=23.5" label. Check for a single remaining boundary before falling back to the median. Rename adjustCustomBins to adjustBinsToOutliers since it now handles generated and quartile bins too.
|
Confirmed and fixed in 2728cba. The <=73 variant of the 20..90 test goes to the discrete binner (only 9 distinct values above 73), so the new test uses 1..46 with "<=35", where Q3 is 35. Before the fix that gave <=23.5 (24) and >23.5 (23). The single-boundary check now runs before the quartile fallback, and adjustCustomBins is renamed to adjustBinsToOutliers with the Javadoc updated. |
Describe changes proposed in this pull request:
<=40or>52. Values inside a bound were counted twice, in the outlier bin and in the first or last data bin. When a whole generated bin fell inside the bound, the request failed withIllegalArgumentException: Invalid range.adjustCustomBinslike custom bins do, and a single boundary left after that becomes the outlier split for all three methods, as it already did for custom bins.adjustCustomBinsno longer adds a bound that is already one of the bins. Custom bins40, 52, 60with a>52value made a[52, 52]bin and counted the 52s twice.Examples with 36 ages (20, 22, ..., 90) plus one special value:
<=40<=35Invalid range: (35..30]>52This happens when the numeric values reach past a special value's bound, e.g. a study view combining a study that records
<=40with one that records exact ages. Quartiles and Generate bins came in with #9198.Checks
Three tests added to
DataBinnerTest, one per case above; all three fail on master.DataBinnerTest,DataBinHelperTest,ClinicalDataBinUtilTest,StudyViewControllerTest,ColumnarStoreStudyViewControllerTestandStudyViewFilterApplierTestpass, andspotless:checkis clean. I can't add labels;fixwould fit.