Skip to content

[MAINT] Update pyriemann mean import - #103

Merged
sappelhoff merged 4 commits into
nbara:masterfrom
bruAristimunha:pyriemann-mean-import
Jul 10, 2026
Merged

sappelhoff merged 4 commits into
nbara:masterfrom
bruAristimunha:pyriemann-mean-import

Conversation

@bruAristimunha

Copy link
Copy Markdown
Contributor

Summary

  • Try the legacy pyriemann mean import first for older releases.
  • Fall back to pyriemann.geometry.mean.gmean when the legacy module emits the deprecation warning or is unavailable.

Why

Newer pyriemann versions deprecate pyriemann.utils.mean, which can fail when deprecations are treated as errors.

Validation

  • python -W error::DeprecationWarning -c "import meegkit.trca"
  • python -W error::DeprecationWarning - <<PY ... trca_regul(...) ... PY
  • python -m pytest tests/test_trca.py -q
  • python -m ruff check meegkit/trca.py

@codecov

codecov Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.12%. Comparing base (1138a60) to head (a99ee0d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #103      +/-   ##
==========================================
+ Coverage   83.02%   83.12%   +0.10%     
==========================================
  Files          25       25              
  Lines        2833     2827       -6     
==========================================
- Hits         2352     2350       -2     
+ Misses        481      477       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nbara

nbara commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Hey @bruAristimunha , thanks! Hope you're well.

Don't you think we could just enforce a newer version of pyriemann?

@nbara
nbara marked this pull request as ready for review July 6, 2026 18:22
@nbara nbara linked an issue Jul 6, 2026 that may be closed by this pull request

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling the pyriemann import breakage — the mean_covariance → gmean fallback in asr.py / trca.py looks right.

One suggestion for the block_covariance hunk specifically. check_function / cov_est_functions have had an unstable availability history: they are absent in pyriemann 0.5 (which exposes only the private _check_est) and are present again in 0.12. So there is a release range in between where the new try/except still raises ImportError from both branches — pyriemann.geometry.covariance doesn't exist yet, and pyriemann.utils.covariance no longer carries the two names. (I verified 0.5 and 0.12 directly; I didn't pin down exactly which 0.6–0.11 releases are affected.)

The public covariances() function sidesteps this — it is present in both pyriemann.utils.covariance and pyriemann.geometry.covariance on 0.5 and 0.12 alike. Since covariances(X, estimator=...) just applies the named estimator to each matrix along the first axis, block_covariance can stack the windows and call it directly, which also lets the try/except go:

def block_covariance(data, window=128, overlap=0.5, padding=True, estimator="cov"):
    """..."""
    from pyriemann.utils.covariance import covariances

    assert 0 <= overlap < 1, "overlap must be < 1"
    blocks = []
    n_chans, n_samples = data.shape
    if padding:  # pad data with zeros
        pad = np.zeros((n_chans, int(window / 2)))
        data = np.concatenate((pad, data, pad), axis=1)

    jump = int(window * overlap)
    ix = 0
    while (ix + window < n_samples):
        blocks.append(data[:, ix:ix + window])
        ix = ix + jump

    return covariances(np.array(blocks), estimator=estimator)

This is behaviour-equivalent to the old per-window est(...) loop (matches np.cov per window on 0.5), and the estimator strings ('scm', 'lwf', 'oas', 'mcd', …) are unchanged. The mean_covariance parts of this PR are orthogonal and unaffected. Happy to push this to your branch if useful.

@bruAristimunha

Copy link
Copy Markdown
Contributor Author

hey @sappelhoff, sure!

I will adjust!

And yes, @nbara, for sure, I will just increase Pyriemann and solve the problem :)

The deprecation-warning-to-error approach was fragile and, on current
pyriemann, silently fell back to a mean_covariance that computes the
wrong logeuclid mean. Prefer the canonical gmean (0.11 rename of
mean_covariance, correct for riemann and logeuclid), fall back to the
old pyriemann.utils.mean module only for pre-0.11.
asr.py called pyriemann.utils.mean.mean_covariance directly, which
raises AttributeError on newer pyriemann where the utils.mean module is
gone -- this was failing CI (test_asr). Resolve mean_covariance via the
same gmean-first fallback as trca, and give covariances.py the same
geometry.covariance-first fallback (was only a deprecation warning, but
breaks at pyriemann 0.14).
@nbara
nbara force-pushed the pyriemann-mean-import branch from 33b4746 to a99ee0d Compare July 7, 2026 12:33
@nbara

nbara commented Jul 7, 2026

Copy link
Copy Markdown
Owner

(@bruAristimunha updated minimum python version and rebased)

@bruAristimunha

Copy link
Copy Markdown
Contributor Author

all good for me @nbara :) Please let me know if you want me to work on this PR or even something else, as I made the modification of Pyriemann, I decided to create this PR

@nbara nbara changed the title Update pyriemann mean import [MAINT] Update pyriemann mean import Jul 7, 2026
@sappelhoff

Copy link
Copy Markdown
Collaborator

@nbara can we get the open ASR PRs in? 🙏 🙂 I am planning to send over a few more AI-assisted ones in the next week or so.

@nbara

nbara commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Yes feel free to merge those I approved, otherwise I will do it later tonight

@sappelhoff

Copy link
Copy Markdown
Collaborator

Thanks, could you invite me as a collaborator then? I currently do not have the rights for it.

@sappelhoff
sappelhoff merged commit 3e66fb1 into nbara:master Jul 10, 2026
7 checks passed
@sappelhoff sappelhoff mentioned this pull request Jul 14, 2026
@larsoner

Copy link
Copy Markdown
Contributor

Was this not in 0.11? Maybe should have been try/except for backward compat

https://github.com/conda-forge/meegkit-feedstock/actions/runs/29774919450/job/88461881957?pr=4

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecated import from pyriemann

4 participants