Skip to content

Select MAPE near-zero rows without expanding duplicate index labels - #1990

Open
Afloat16 wants to merge 1 commit into
evidentlyai:mainfrom
Afloat16:fix/mape-duplicate-row-index-20261112
Open

Afloat16 wants to merge 1 commit into
evidentlyai:mainfrom
Afloat16:fix/mape-duplicate-row-index-20261112

Conversation

@Afloat16

Copy link
Copy Markdown

Problem

MAPE zero handling selects near-zero targets, then uses their index labels to drop or replace rows. With duplicate labels, drop also removes unrelated observations sharing those labels. On pandas 2.3, replace raises InvalidIndexError instead of producing the report.

For targets [0, 1, 2, 0, 4, 8], predictions [2, 2, 1, 3, 6, 8], and index [7, 7, 8, 8, 9, 9], dropping the two near-zero target rows should produce MAPE 50%. The current code drops four rows and reports 25%.

Change

Keep the boolean near-zero mask and use it directly for both row filtering and replacement. This preserves the individual observations even when their index labels are repeated, including MultiIndex labels.

The zero threshold, replacement value, denominator formula, and near_zero_values counter are unchanged. In particular, this is separate from #1933 (the near-zero row counter) and #1986 (negative-target denominators).

Validation

  • Eleven new regression cases: base code has 8 failures and 3 passing controls.
  • Fixed code: 12 tests pass including the existing native regression-report smoke test.
  • Tests cover duplicate integer/string/MultiIndex labels, unique-label controls, hand-calculated mean and sample standard deviation, unchanged input frames, and none handling.
  • Native Report([MAPE(...)]) calls verify that changing only row labels does not change the reported metric.
  • Pinned Ruff 0.3.7 lint/format checks and git diff --check pass.

The full repository test suite was not run. This change corrects selection of evaluation rows; it does not claim improved model prediction quality.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant