Skip to content

load_audit() returns masks as pandas Series, so every use needs .to_numpy().astype(int) #1133

Open

Description

@yakew7

Where: faircode/benchmark.py (AuditData), faircode/SPEC.md section 11, tests/test_load_audit.py, the explainers' code blocks.

Current gap: AuditData.masks maps each attribute to a boolean pandas Series aligned with the filtered rows. Almost every use in an explainer or notebook starts by converting it: data.masks["sex"].to_numpy().astype(int) appears more than 30 times in the explainers added in the last two weeks, and a missing .astype(int) silently changes arithmetic such as group = sex * 2 + race (booleans add as booleans). It also invites index-alignment mistakes when the Series is combined with arrays.

Suggested approach: add small accessors to AuditData: group(name) returning a plain 0/1 integer array, and test_group(name) / train_group(name) returning the slices for the manifest's split, keeping masks as it is. Document them in the SPEC and switch two explainer code blocks to them to show the shorter form.

Done when: the accessors exist with tests (dtype, alignment with idx_test, unknown attribute error), the SPEC lists them, and at least two explainers use them with unchanged output.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions