What's wrong
RFMTransformer.fit branches on whether X has a .columns attribute. Every test in tests/test_rfm.py fits a pandas.DataFrame, so the bare-ndarray branch (the one that synthesizes feature_names_in_ as ["x0", "x1", ...]) never runs. pytest --cov-report=term-missing shows it uncovered today.
Because RFMTransformer requires the columns donor_id, gift_date, gift_amount by name, fitting it on an unlabelled ndarray can never supply those names — so the correct, already-implemented behaviour is that it raises a clear ValueError naming the missing columns instead of failing later with a confusing KeyError. That behaviour is currently unverified.
Where
| File |
Locate with |
philanthropy/preprocessing/_rfm.py |
grep -n "X_arr = np.asarray(X)" philanthropy/preprocessing/_rfm.py |
What to change
No source change — this is test-only.
- Open
tests/test_rfm.py and look at test_rfm_transformer_validation (locate with grep -n "def test_rfm_transformer_validation" tests/test_rfm.py) for the existing style of asserting on _validate_input's error.
- Add a new test after it that calls
RFMTransformer().fit(np.ones((3, 3))) (a bare ndarray, no column labels) and asserts it raises ValueError naming the required columns. tests/test_rfm.py doesn't import numpy yet — add import numpy as np at the top alongside the existing pandas/pytest imports.
Tests to add or extend
- File:
tests/test_rfm.py
- Add:
test_rfm_transformer_ndarray_input_raises_missing_columns
def test_rfm_transformer_ndarray_input_raises_missing_columns():
with pytest.raises(ValueError, match="donor_id"):
RFMTransformer().fit(np.ones((3, 3)))
(Check the top of the file for the existing numpy import name before adding the test.)
Done when
python -m pytest tests/test_rfm.py --cov=philanthropy.preprocessing._rfm -q
python -m coverage report --include='philanthropy/preprocessing/_rfm.py' --fail-under=100
make ci
make riskcov
The coverage report --fail-under=100 line exits non-zero until _rfm.py reads fully covered; make ci and make riskcov must also stay green.
First time here?
Read CONTRIBUTING.md and AGENTS.md. Add a ## [Unreleased] CHANGELOG entry and yourself to CONTRIBUTORS.md in the same PR.
What's wrong
RFMTransformer.fitbranches on whetherXhas a.columnsattribute. Every test intests/test_rfm.pyfits apandas.DataFrame, so the bare-ndarraybranch (the one that synthesizesfeature_names_in_as["x0", "x1", ...]) never runs.pytest --cov-report=term-missingshows it uncovered today.Because
RFMTransformerrequires the columnsdonor_id,gift_date,gift_amountby name, fitting it on an unlabelledndarraycan never supply those names — so the correct, already-implemented behaviour is that it raises a clearValueErrornaming the missing columns instead of failing later with a confusingKeyError. That behaviour is currently unverified.Where
philanthropy/preprocessing/_rfm.pygrep -n "X_arr = np.asarray(X)" philanthropy/preprocessing/_rfm.pyWhat to change
No source change — this is test-only.
tests/test_rfm.pyand look attest_rfm_transformer_validation(locate withgrep -n "def test_rfm_transformer_validation" tests/test_rfm.py) for the existing style of asserting on_validate_input's error.RFMTransformer().fit(np.ones((3, 3)))(a barendarray, no column labels) and asserts it raisesValueErrornaming the required columns.tests/test_rfm.pydoesn't importnumpyyet — addimport numpy as npat the top alongside the existingpandas/pytestimports.Tests to add or extend
tests/test_rfm.pytest_rfm_transformer_ndarray_input_raises_missing_columns(Check the top of the file for the existing
numpyimport name before adding the test.)Done when
python -m pytest tests/test_rfm.py --cov=philanthropy.preprocessing._rfm -q python -m coverage report --include='philanthropy/preprocessing/_rfm.py' --fail-under=100 make ci make riskcovThe
coverage report --fail-under=100line exits non-zero until_rfm.pyreads fully covered;make ciandmake riskcovmust also stay green.First time here?
Read CONTRIBUTING.md and AGENTS.md. Add a
## [Unreleased]CHANGELOG entry and yourself toCONTRIBUTORS.mdin the same PR.