Skip to content

Commit ec1cedb

Browse files
Fixing issues 123. (#177)
* Fixing issues 123. * Fixing coverage. * Linting
1 parent 645cb12 commit ec1cedb

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

pylossless/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ def pipeline_fixture():
2929
config["find_breaks"]["t_start_after_previous"] = 1
3030
config["find_breaks"]["t_stop_before_next"] = 0
3131
config["ica"]["ica_args"]["run1"]["max_iter"] = 5000
32+
33+
# Testing when passing the config object directly...
34+
pipeline = ll.LosslessPipeline("test_config.yaml", config)
35+
pipeline = ll.LosslessPipeline(config=config)
3236
config.save("test_config.yaml")
37+
38+
# Testing when passing a string...
3339
pipeline = ll.LosslessPipeline("test_config.yaml")
40+
41+
# Testing when passing a Path...
42+
pipeline = ll.LosslessPipeline(Path("test_config.yaml"))
43+
3444
not_in_1020 = ["EXG1", "EXG2", "EXG3", "EXG4", "EXG5", "EXG6", "EXG7", "EXG8"]
3545
pipeline.raw = raw.pick("eeg", exclude=not_in_1020).load_data()
3646
pipeline.run_with_raw(pipeline.raw)

pylossless/pipeline.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class LosslessPipeline:
417417
418418
Parameters
419419
----------
420-
config_fname : pathlib.Path
420+
config_path : pathlib.Path
421421
path to config file specifying the parameters to be used
422422
in the pipeline.
423423
@@ -429,7 +429,7 @@ class LosslessPipeline:
429429
:class:`~pylossless.flagging.FlaggedChs`,
430430
:class:`~pylossless.flagging.FlaggedEpochs`, and
431431
:class:`~pylossless.flagging.FlaggedICs`, respectively.
432-
config_fname : pathlib.Path
432+
config_path : pathlib.Path
433433
path to the config file specifying the parameters to be used in the
434434
in the pipeline.
435435
config : dict
@@ -445,23 +445,31 @@ class LosslessPipeline:
445445
during the pipeline.
446446
"""
447447

448-
def __init__(self, config_fname=None):
448+
def __init__(self, config_path=None, config=None):
449449
"""Initialize class.
450450
451451
Parameters
452452
----------
453-
config_fname : pathlib.Path
454-
path to config file specifying the parameters to be used
455-
in the pipeline.
453+
config_path : pathlib.Path | str | None
454+
Path to config file specifying the parameters to be used in the pipeline.
455+
456+
config : pylossless.config.Config | None
457+
:class:`pylossless.config.Config` object for the pipeline.
456458
"""
457459
self.flags = {
458460
"ch": FlaggedChs(self),
459461
"epoch": FlaggedEpochs(self),
460462
"ic": FlaggedICs(),
461463
}
462-
self.config_fname = config_fname
463-
if config_fname:
464+
if config:
465+
self.config = config
466+
if config_path is None:
467+
self.config_path = "._tmp_pylossless.yaml"
468+
elif config_path:
469+
self.config_path = Path(config_path)
464470
self.load_config()
471+
else:
472+
self.config_path = None
465473
self.raw = None
466474
self.ica1 = None
467475
self.ica2 = None
@@ -483,13 +491,13 @@ def _repr_html_(self):
483491
]
484492
flagged_times = _sum_flagged_times(self.raw, lossless_flags)
485493

486-
config_fname = self.config_fname
494+
config_path = self.config_path
487495
raw = self.raw.filenames if self.raw else "Not specified"
488496

489497
html = "<h3>LosslessPipeline</h3>"
490498
html += "<table>"
491499
html += f"<tr><td><strong>Raw</strong></td><td>{raw}</td></tr>"
492-
html += f"<tr><td><strong>Config</strong></td><td>{config_fname}</td></tr>"
500+
html += f"<tr><td><strong>Config</strong></td><td>{config_path}</td></tr>"
493501
html += "</table>"
494502

495503
# Flagged Channels
@@ -518,9 +526,21 @@ def _repr_html_(self):
518526

519527
return html
520528

529+
@property
530+
def config_fname(self):
531+
warn('config_fname is deprecated and will be removed from future versions.',
532+
DeprecationWarning)
533+
return self.config_path
534+
535+
@config_fname.setter
536+
def config_fname(self, config_path):
537+
warn('config_fname is deprecated and will be removed from future versions.',
538+
DeprecationWarning)
539+
self.config_path = config_path
540+
521541
def load_config(self):
522542
"""Load the config file."""
523-
self.config = Config().read(self.config_fname)
543+
self.config = Config().read(self.config_path)
524544

525545
def _check_sfreq(self):
526546
"""Make sure sampling frequency is an integer.
@@ -1215,7 +1235,7 @@ def load_ll_derivative(self, derivatives_path):
12151235
)
12161236
self.flags["ic"].load_tsv(iclabels_bidspath.fpath)
12171237

1218-
self.config_fname = bpath.update(
1238+
self.config_path = bpath.update(
12191239
extension=".yaml", suffix="ll_config", check=False
12201240
)
12211241
self.load_config()

pylossless/tests/test_pipeline.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ def test_find_breaks(logging):
4444
else:
4545
pipeline.find_breaks()
4646
Path(config_fname).unlink() # delete config file
47+
48+
49+
def test_deprecation():
50+
"""Test the config_name property added for deprecation."""
51+
config = ll.config.Config()
52+
config.load_default()
53+
pipeline = ll.LosslessPipeline(config=config)
54+
# with pytest.raises(DeprecationWarning, match=f"config_fname is deprecated"):
55+
# DeprecationWarning are currently ignored by pytest given our toml file
56+
pipeline.config_fname = pipeline.config_fname

pylossless/tests/test_simulated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@pytest.mark.parametrize("pipeline", [(pipeline)])
2727
def test_simulated_raw(pipeline):
2828
"""Test pipeline on simulated EEG."""
29-
with pytest.warns(RuntimeWarning, match="sampling frequency"):
29+
with pytest.warns(RuntimeWarning, match="The Raw sampling frequency is"):
3030
pipeline._check_sfreq()
3131
# This file should have been downsampled
3232
assert pipeline.raw.info["sfreq"] == 600
@@ -59,5 +59,5 @@ def test_simulated_raw(pipeline):
5959
assert "EEG 054" in pipeline.flags["ch"]["bridged"]
6060

6161
# Delete temp config file
62-
tmp_config_fname = Path(pipeline.config_fname).absolute()
63-
tmp_config_fname.unlink()
62+
tmp_config_path = Path(pipeline.config_path).absolute()
63+
tmp_config_path.unlink()

0 commit comments

Comments
 (0)