Repository navigation
[MAINT] Update pyriemann mean import - #103
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Hey @bruAristimunha , thanks! Hope you're well. Don't you think we could just enforce a newer version of pyriemann? |
sappelhoff
left a comment
There was a problem hiding this comment.
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.
|
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).
33b4746 to
a99ee0d
Compare
|
(@bruAristimunha updated minimum python version and rebased) |
|
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 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. |
|
Yes feel free to merge those I approved, otherwise I will do it later tonight |
|
Thanks, could you invite me as a collaborator then? I currently do not have the rights for it. |
|
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 |
Summary
pyriemann.geometry.mean.gmeanwhen 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(...) ... PYpython -m pytest tests/test_trca.py -qpython -m ruff check meegkit/trca.py