Skip to content

test: PlannedGivingIntentScorer.predict_intent_score never exercises its single-class fallback #56

Description

@shivamlalakiya

What's wrong

PlannedGivingIntentScorer.predict_intent_score short-circuits to
np.zeros(proba.shape[0]) when predict_proba returns fewer than two columns
(the single-class-seen-at-fit case). This is the same shape of guard as the one
fixed for PropensityScorer.predict_proba in #50, but in a different class and
method — nothing in tests/test_planned_giving.py fits on single-label data, so
this branch has never run.

Where

File Locate with
philanthropy/models/_planned_giving.py grep -n "proba.shape\[1\] < 2" philanthropy/models/_planned_giving.py

What to change

No source change — this is test-only.

  1. Open tests/test_planned_giving.py and look at the existing
    predict_intent_score test (locate with
    grep -n "def test.*intent_score" tests/test_planned_giving.py) for fixture
    style.
  2. Add a test that fits PlannedGivingIntentScorer on a y containing only one
    label, then calls predict_intent_score and asserts every score is 0.0.

Tests to add or extend

  • File: tests/test_planned_giving.py
  • Add: test_predict_intent_score_single_class_returns_zeros

Done when

python -m pytest tests/test_planned_giving.py --cov=philanthropy.models._planned_giving --cov-report=term-missing -q

philanthropy/models/_planned_giving.py reads 100% covered with an empty
Missing column.

Metadata

Metadata

Assignees

No one assigned

    Labels

    beginnerNo fundraising domain knowledge neededeasySmall, well-scoped, single-file changegood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions