Skip to content

MNT Re-examine the check_is_fitted try/except pattern in _AdversarialFairness._validate_input #1657

Closed

Description

@romanlutz

Context

fairlearn/adversarial/_adversarial_mitigation.py#L690 wraps check_is_fitted in a try/except NotFittedError that has carried a # TODO check this for a long time:

try:  # TODO check this
    check_is_fitted(self)
    is_fitted = True
except NotFittedError:
    is_fitted = False

The try/except is used here to probe fit state — _validate_input legitimately needs to know whether the estimator has been fit yet so it can decide whether to call __setup and re-initialize.

Suggested action

Decide whether this probing pattern is appropriate and either remove the # TODO (with a brief justification) or refactor it. Options worth considering:

  • Replace with a direct attribute check on the fitted attribute (e.g. hasattr(self, "backendEngine_")), which avoids the round-trip through an exception path.
  • Keep the try/except but drop the stale # TODO and add a one-line explanation that we are intentionally probing the fit state.

Either resolution is small and self-contained.

Surfaced during a repo-cleanup audit by @romanlutz.

Activity

  1. added
    maintenance
    on Jun 12, 2026
  2. hiSandog commented on Jun 29, 2026

    @hiSandog

    Re-examining check_is_fitted handling sounds worthwhile because broad try/except patterns can hide real estimator bugs. It may help to separate "estimator is not fitted" from "estimator validation raised for another reason" and only recover from the former. A regression test with a deliberately broken estimator that raises a different exception would make sure the validation path does not swallow actionable errors.

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

    maintenance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions