Skip to content

Commit

Permalink
Merge pull request #35 from wmvanvliet/update-workflows
Browse files Browse the repository at this point in the history
Use newer versions of github actions
  • Loading branch information
wmvanvliet authored Oct 15, 2024
2 parents b88ab07 + 1483c47 commit a6fffe2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
_MNE_BRAIN_TRACES_AUTO: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v2
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Merge with upstream
run: |
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Cache Pip
id: cache-pip
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-cache
Expand Down Expand Up @@ -79,17 +79,8 @@ jobs:
cd doc;
make html;
# Save the outputs
#- store_artifacts:
# path: doc/_build/html/
# destination: dev

#- persist_to_workspace:
# root: doc/_build
# paths:
# - html
- name: Save HTML as artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: docs
path: doc/_build/html
8 changes: 4 additions & 4 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 2 additions & 1 deletion mne_rsa/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def count_rank_tie(ranks):


def _consolidate_masks(masks):
if type(masks[0]) == slice:
"""Compute the union of multiple masks."""
if type(masks[0]) is slice:
mask = slice(None)
else:
mask = masks[0]
Expand Down
4 changes: 2 additions & 2 deletions mne_rsa/sensor_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ def rdm_epochs(
]
for rdm in rdm_gen:
rdm = distance.squareform(rdm)
rdm = np.insert(rdm, nan_locations, np.NaN, axis=0)
rdm = np.insert(rdm, nan_locations, np.NaN, axis=1)
rdm = np.insert(rdm, nan_locations, np.nan, axis=0)
rdm = np.insert(rdm, nan_locations, np.nan, axis=1)
# Can't use squareform to convert back due to the NaNs.
yield rdm[np.triu_indices(len(rdm), 1)]

Expand Down
34 changes: 17 additions & 17 deletions tests/test_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_spearman(self):
model_rdm = np.array([2, 3, 3.5])
assert next(rsa_gen(data_rdm, model_rdm, metric="spearman")) == 1.0

data_rdm = rdm_gen([[np.NaN, 2, 3, 4, 5]])
model_rdm = np.array([2, np.NaN, 3.5, 4, 5])
data_rdm = rdm_gen([[np.nan, 2, 3, 4, 5]])
model_rdm = np.array([2, np.nan, 3.5, 4, 5])
assert (
next(rsa_gen(data_rdm, model_rdm, metric="spearman", ignore_nan=True))
== 1.0
Expand All @@ -48,8 +48,8 @@ def test_pearson(self):
model_rdm = np.array([2, 3, 3.5])
assert next(rsa_gen(data_rdm, model_rdm, metric="pearson")) < 1.0

data_rdm = rdm_gen([[np.NaN, 2, 3, 4, 5]])
model_rdm = np.array([2, np.NaN, 3.5, 4, 5])
data_rdm = rdm_gen([[np.nan, 2, 3, 4, 5]])
model_rdm = np.array([2, np.nan, 3.5, 4, 5])
assert (
next(rsa_gen(data_rdm, model_rdm, metric="pearson", ignore_nan=True)) < 1.0
)
Expand All @@ -61,8 +61,8 @@ def test_kendall_tau_a(self):
rsa_val = next(rsa_gen(data_rdm, model_rdm, metric="kendall-tau-a"))
assert rsa_val == 2 / 3

data_rdm = rdm_gen([[1, np.NaN, 2, 3, 4]])
model_rdm = np.array([1, 2, 3, 3, np.NaN])
data_rdm = rdm_gen([[1, np.nan, 2, 3, 4]])
model_rdm = np.array([1, 2, 3, 3, np.nan])
rsa_val = next(
rsa_gen(data_rdm, model_rdm, metric="kendall-tau-a", ignore_nan=True)
)
Expand All @@ -76,8 +76,8 @@ def test_regression(self):
rsa_val = next(rsa_gen(data_rdm, [model_rdm1, model_rdm2], metric="regression"))
assert_allclose(rsa_val, [3, 5])

model_rdm1 = np.array([-1, np.NaN, 0, 1, 1])
model_rdm2 = np.array([1, 3, -2, 1, np.NaN])
model_rdm1 = np.array([-1, np.nan, 0, 1, 1])
model_rdm2 = np.array([1, 3, -2, 1, np.nan])
data_rdm = rdm_gen([3 * model_rdm1 + 5 * model_rdm2])
rsa_val = next(
rsa_gen(
Expand All @@ -95,9 +95,9 @@ def test_partial(self):
rsa_val = next(rsa_gen(data_rdm, [model_rdm1, model_rdm2], metric="partial"))
assert_allclose(rsa_val, [0.919145, 0.912871])

model_rdm1 = np.array([1, np.NaN, 2, 3, 4, 4])
model_rdm2 = np.array([0, 0, 0, 1, 1, np.NaN])
data_rdm = rdm_gen([[2, np.NaN, 4, 15, 20, np.NaN]])
model_rdm1 = np.array([1, np.nan, 2, 3, 4, 4])
model_rdm2 = np.array([0, 0, 0, 1, 1, np.nan])
data_rdm = rdm_gen([[2, np.nan, 4, 15, 20, np.nan]])
rsa_val = next(
rsa_gen(
data_rdm, [model_rdm1, model_rdm2], metric="partial", ignore_nan=True
Expand All @@ -116,9 +116,9 @@ def test_partial_spearman(self):
)
assert_allclose(rsa_val, [0, 2 / 3], atol=1e-15)

model_rdm1 = np.array([1, np.NaN, 2, 3, 4, 4])
model_rdm2 = np.array([0, 0, 0, 1, 1, np.NaN])
data_rdm = rdm_gen([[2, np.NaN, 4, 20, 15, np.NaN]])
model_rdm1 = np.array([1, np.nan, 2, 3, 4, 4])
model_rdm2 = np.array([0, 0, 0, 1, 1, np.nan])
data_rdm = rdm_gen([[2, np.nan, 4, 20, 15, np.nan]])
rsa_val = next(
rsa_gen(
data_rdm,
Expand All @@ -141,10 +141,10 @@ def test_invalid_metric(self):
next(rsa_gen(rdm_gen([rdm()]), rdm(), metric="partial-spearman"))

def test_nan(self):
"""Test whether NaNs generate an error when appropriate."""
assert np.isnan(next(rsa_gen(rdm_gen([[1, 2, np.NaN, 4, 5, 6]]), rdm())))
"""Test whether nans generate an error when appropriate."""
assert np.isnan(next(rsa_gen(rdm_gen([[1, 2, np.nan, 4, 5, 6]]), rdm())))
assert_allclose(
next(rsa_gen(rdm_gen([[1, 2, np.NaN, 4, 5, 6]]), rdm(), ignore_nan=True)),
next(rsa_gen(rdm_gen([[1, 2, np.nan, 4, 5, 6]]), rdm(), ignore_nan=True)),
1,
atol=1e-15,
)
Expand Down

0 comments on commit a6fffe2

Please sign in to comment.