Skip to content

Commit d9ccd27

Browse files
Fix Python 3.10 compatibility: replace *unpacking in subscripts
Co-authored-by: bruAristimunha <[email protected]>
1 parent 3b1c1a5 commit d9ccd27

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

eegdash/features/feature_bank/complexity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def preprocess(self, x, m=2, r=0.2, l=1):
3636
counts_m = np.empty((*x.shape[:-1], (x.shape[-1] - m + 1) // l))
3737
counts_mp1 = np.empty((*x.shape[:-1], (x.shape[-1] - m) // l))
3838
for i in np.ndindex(x.shape[:-1]):
39-
counts_m[*i, :] = _channel_app_samp_entropy_counts(x[i], m, rr[i], l)
40-
counts_mp1[*i, :] = _channel_app_samp_entropy_counts(x[i], m + 1, rr[i], l)
39+
counts_m[i + (slice(None),)] = _channel_app_samp_entropy_counts(x[i], m, rr[i], l)
40+
counts_mp1[i + (slice(None),)] = _channel_app_samp_entropy_counts(x[i], m + 1, rr[i], l)
4141
return counts_m, counts_mp1
4242

4343

@@ -62,7 +62,7 @@ def complexity_sample_entropy(counts_m, counts_mp1):
6262
def complexity_svd_entropy(x, m=10, tau=1):
6363
x_emb = np.empty((*x.shape[:-1], (x.shape[-1] - m + 1) // tau, m))
6464
for i in np.ndindex(x.shape[:-1]):
65-
x_emb[*i, :, :] = _create_embedding(x[i], m, tau)
65+
x_emb[i + (slice(None), slice(None))] = _create_embedding(x[i], m, tau)
6666
s = np.linalg.svdvals(x_emb)
6767
s /= s.sum(axis=-1, keepdims=True)
6868
return -np.sum(s * np.log(s), axis=-1)

eegdash/features/feature_bank/dimensionality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def dimensionality_higuchi_fractal_dim(x, k_max=10, eps=1e-7):
2626
for i in np.ndindex(x.shape[:-1]):
2727
for k in range(1, k_max + 1):
2828
for m in range(k):
29-
L_km[m] = np.mean(np.abs(np.diff(x[*i, m:], n=k)))
29+
L_km[m] = np.mean(np.abs(np.diff(x[i + (slice(m, None),)], n=k)))
3030
L_k[k - 1] = (N - 1) * np.sum(L_km[:k]) / (k**3)
3131
L_k = np.maximum(L_k, eps)
3232
hfd[i] = np.linalg.lstsq(log_k, np.log(L_k))[0][0]

tests/test_features.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Test for features module Python 3.10+ compatibility."""
2+
3+
import pytest
4+
5+
6+
def test_import_features_module():
7+
"""Test that the features module can be imported without syntax errors.
8+
9+
This test ensures Python 3.10+ compatibility by verifying that:
10+
1. Type annotations with list[], type[], and | syntax work (via __future__ imports)
11+
2. No Python 3.11+ exclusive syntax is used (like *unpacking in subscripts)
12+
"""
13+
try:
14+
import eegdash.features
15+
assert eegdash.features is not None
16+
except SyntaxError as e:
17+
pytest.fail(f"SyntaxError when importing eegdash.features: {e}")
18+
except ImportError as e:
19+
pytest.fail(f"ImportError when importing eegdash.features: {e}")
20+
21+
22+
def test_import_features_submodules():
23+
"""Test that all features submodules can be imported."""
24+
submodules = [
25+
"eegdash.features.inspect",
26+
"eegdash.features.extractors",
27+
"eegdash.features.serialization",
28+
"eegdash.features.datasets",
29+
"eegdash.features.decorators",
30+
"eegdash.features.feature_bank",
31+
"eegdash.features.feature_bank.complexity",
32+
"eegdash.features.feature_bank.dimensionality",
33+
"eegdash.features.feature_bank.signal",
34+
"eegdash.features.feature_bank.spectral",
35+
"eegdash.features.feature_bank.connectivity",
36+
"eegdash.features.feature_bank.csp",
37+
]
38+
39+
for module_name in submodules:
40+
try:
41+
__import__(module_name)
42+
except SyntaxError as e:
43+
pytest.fail(f"SyntaxError when importing {module_name}: {e}")
44+
except ImportError as e:
45+
# Some imports might fail due to missing dependencies, that's ok
46+
# We only care about SyntaxError
47+
pass
48+
49+
50+
def test_features_basic_functionality():
51+
"""Test basic features module functionality."""
52+
from eegdash.features import (
53+
get_all_features,
54+
get_all_feature_extractors,
55+
get_all_feature_kinds,
56+
)
57+
58+
# These should return lists without errors
59+
features = get_all_features()
60+
assert isinstance(features, list)
61+
62+
extractors = get_all_feature_extractors()
63+
assert isinstance(extractors, list)
64+
65+
kinds = get_all_feature_kinds()
66+
assert isinstance(kinds, list)

0 commit comments

Comments
 (0)