instadeepai / instadeepai/winnow

refactor: `DatabaseGroundedFDRControl.fit` mutates its input DataFrame

Open
#228 0 comments 0 reactions 0 assignees View on GitHub
refactor
Dominant language
Python
Stars
11
Forks
2
Avg merge
1d 8h
Merged PRs (30d)
1

Description

## Summary

`DatabaseGroundedFDRControl.fit` (`winnow/fdr/database_grounded.py`) changes the
DataFrame you pass in. A `fit` should really leave its input alone. This was raised in
a review but unrelated to the current PR, so tracking it here.

## Description & Purpose

Right now `fit` writes straight back into the caller's DataFrame: it overwrites
`sequence` and `prediction`, and adds `num_matches` and `correct`. Two issues
with that:

- Those side effects are easy to miss, since nothing about `fit` hints the input
will change.
- If someone passes a slice, the writes hit a copy, pandas raises
`SettingWithCopyWarning`, and the method silently fails.

Proposed fixes, roughly in order of preference:

1. Take what we actually need instead of a whole DataFrame: `sequence`,
`prediction`, and confidence. Cleaner contract, no column-layout coupling.
2. If we keep the DataFrame, copy it first (`dataset = dataset.copy()`) and work
on the copy. Return it if callers want the `num_matches` / `correct` columns.
3. Either way, fix the docstring and possibly also the function the name to match what it does,
e.g. `estimate`, `calibrate`, or `add_calibration_columns`. Note `fit` is part of
the `FDRControl` base interface (`winnow/fdr/base.py`), so a rename touches
`NonParametricFDRControl` and the call sites too.

Worth noting `NonParametricFDRControl.fit` already sidesteps this by working on
arrays via `.to_numpy()`, so option 1 would line the two up.

## Additional Notes

- Check `tests/fdr/` and call sites before changing the signature or name, and
make sure nothing downstream relies on the mutated columns.

### Description & Purpose:

_No response_

### Additional Notes:

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in winnow/fdr/database_grounded.py and compare DatabaseGroundedFDRControl.fit with NonParametricFDRControl.fit, then inspect the FDRControl interface in winnow/fdr/base.py. Search tests/fdr/ and call sites for reliance on mutated columns or the current signature before choosing an approach. Done means fit no longer mutates caller-owned input, its contract and docstring are consistent, and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.