Skip to content

Consider retaining sex in anonymize_info() #13637

Closed

Description

@cbrnr

Currently, anonymize_info() preserves age (instead of the full birthday), which is both anonymized and useful for many analyses (and there is no way to disable this behavior). The same argument seems to apply to sex, but this field is currently dropped (set to 0 for unknown).

In #8130, there appeared to be consensus that keeping sex would be acceptable, but it was never implemented (or exposed via a parameter). Would it make sense to retain sex by default (in line with keeping age), or at least add a parameter to control this? I'm happy to submit a PR.

Activity

  1. cbrnr commented on Feb 6, 2026

    @cbrnr
    ContributorAuthor

    I just noticed that keep_his=True actually retains not only his_id, but also sex and hand (see https://github.com/mne-tools/mne-python/blob/main/mne/_fiff/meas_info.py#L3721-L3731). This is undocumented behavior, so we definitely need to fix something here. I suggest that keep_his=True only retains his_id, and that we keep sex and hand (just like we keep age). Alternatively, I would add two new parameters keep_sex=False and keep_hand=False, but then we should discuss dropping the age as well in order to have a "fully anonymized" data set in the sense that not even age is kept.

  2. larsoner commented on Feb 9, 2026

    @larsoner
    Member

    FYI HIS is an acronym, "hospital information system". It is possible that handedness and sex might also (have historically) come from that system, not sure...

    But anyhow, the proposal to add keep_sex and keep_hand is okay but then we'd also want keep_his_id instead of keep_his, and it would create code churn for people, need deprecation, etc. To minimize disruption and stay backward compatible, why don't we do keep_his: tuple[Literal["hand", "id", "sex"], ...] | bool where True is an alias for ("hand", "id", "sex"), and False is an alias for (). Old code still works as it did before with bool, new code can be more granular in terms of which bits of information are kept by passing a tuple of desired fields to keep. And as part of this, documenting that True is an alias is an alias of that tuple will make clear what is kept. The disadvantage is a slight misnomer in the keep_his= (which would be slightly nicer as keep=) but to me that little bit of pain is worth not forcing people to modify their code.

  3. cbrnr commented on Feb 9, 2026

    @cbrnr
    ContributorAuthor

    Good idea!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions