Skip to content

Commit 6a53b35

Browse files
authored
Merge branch 'checkmodes' into main
2 parents 49d9e76 + 825c4a4 commit 6a53b35

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

fooof/objs/fit.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
_debug : bool
4646
Whether the object is set in debug mode.
4747
This should be controlled by using the `set_debug_mode` method.
48-
_check_freqs: bool
49-
Whether to checked added added frequency values for even linear spacing.
50-
_check_data : bool
51-
Whether to check added data for NaN or Inf values, and fail out if present.
52-
This should be controlled by using the `set_check_data_mode` method.
48+
_check_data, _check_freqs : bool
49+
Whether to check added inputs for incorrect inputs, failing if present.
50+
Frequency data is checked for linear spacing.
51+
Power values are checked for data for NaN or Inf values.
52+
These modes default to True, and can be controlled with the `set_check_modes` method.
5353
5454
Code Notes
5555
----------
@@ -737,19 +737,25 @@ def set_debug_mode(self, debug):
737737

738738
self._debug = debug
739739

740-
741-
def set_check_freqs_mode(self, check_freqs):
742-
"""Set check freqs mode, which controls if an error is raised for unevenly spaced input frequencies.
740+
741+
def set_check_modes(self, check_freqs=None, check_data=None):
742+
"""Set check modes, which controls if an error is raised based on check on the inputs.
743743
744744
Parameters
745745
----------
746-
check_freqs : bool
747-
Whether to run in check freqs mode.
746+
check_freqs : bool, optional
747+
Whether to run in check freqs mode, which checks the frequency data.
748+
check_data : bool, optional
749+
Whether to run in check data mode, which checks the power spectrum values data.
748750
"""
749751

750-
self._check_freqs = check_freqs
752+
if check_freqs is not None:
753+
self._check_freqs = check_freqs
754+
if check_data is not None:
755+
self._check_data = check_data
751756

752757

758+
# This kept for backwards compatibility, but to be removed in 2.0 in favor of `set_check_modes`
753759
def set_check_data_mode(self, check_data):
754760
"""Set check data mode, which controls if an error is raised if NaN or Inf data are added.
755761
@@ -759,7 +765,7 @@ def set_check_data_mode(self, check_data):
759765
Whether to run in check data mode.
760766
"""
761767

762-
self._check_data = check_data
768+
self.set_check_modes(check_data=check_data)
763769

764770

765771
def set_run_modes(self, debug, check_freqs, check_data):
@@ -774,9 +780,9 @@ def set_run_modes(self, debug, check_freqs, check_data):
774780
check_data : bool
775781
Whether to run in check data mode.
776782
"""
777-
self._debug = debug
778-
self._check_freqs = check_freqs
779-
self._check_data = check_data
783+
784+
self.set_debug_mode(debug)
785+
self.set_check_modes(check_freqs, check_data)
780786

781787

782788
def to_df(self, peak_org):

fooof/tests/objs/test_fit.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,24 @@ def test_fooof_debug():
414414
with raises(FitError):
415415
tfm.fit(*gen_power_spectrum([3, 50], [50, 2], [10, 0.5, 2, 20, 0.3, 4]))
416416

417-
def test_fooof_check_data():
418-
"""Test FOOOF in with check data mode turned off, including with NaN data."""
417+
def test_fooof_set_check_modes(tfm):
418+
"""Test changing check_modes using set_check_modes, and that checks get turned off.
419+
Note that testing for checks raising errors happens in test_fooof_checks.`"""
419420

420421
tfm = FOOOF(verbose=False)
421422

422-
tfm.set_check_data_mode(False)
423+
tfm.set_check_modes(False, False)
424+
assert tfm._check_freqs is False
423425
assert tfm._check_data is False
424426

425-
# Add data, with check data turned off
426-
# In check data mode, adding data with NaN should run
427-
freqs = gen_freqs([3, 50], 0.5)
427+
# Add bad frequency data, with check freqs turned off
428+
freqs = np.array([1, 2, 4])
429+
powers = np.array([1, 2, 3])
430+
tfm.add_data(freqs, powers)
431+
assert tfm.has_data
432+
433+
# Add bad power values data, with check data turned off
434+
freqs = gen_freqs([3, 30], 1)
428435
powers = np.ones_like(freqs) * np.nan
429436
tfm.add_data(freqs, powers)
430437
assert tfm.has_data
@@ -433,6 +440,11 @@ def test_fooof_check_data():
433440
tfm.fit()
434441
assert not tfm.has_model
435442

443+
# Reset check modes to true
444+
tfm.set_check_modes(True, True)
445+
assert tfm._check_freqs is True
446+
assert tfm._check_data is True
447+
436448
def test_fooof_to_df(tfm, tbands, skip_if_no_pandas):
437449

438450
df1 = tfm.to_df(2)

0 commit comments

Comments
 (0)