Skip to content

Commit

Permalink
Add test for deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
vferat committed Sep 13, 2023
1 parent 8e1ddf7 commit 8b491e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
18 changes: 9 additions & 9 deletions pycrostates/segmentation/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def compute_parameters(self, norm_gfp: bool = True, return_dist: bool = False):
durations of each segments assigned to a given state. Each value is
expressed in seconds (s).
Warnings
warnings
--------
When working with `~mne.Epochs`, this method will put together segments of all
epochs. This could lead to wrong interpretation especially on state durations.
Expand Down Expand Up @@ -222,7 +222,7 @@ def compute_transition_matrix(
-------
%(transition_matrix)s
Warnings
warnings
--------
When working with `~mne.Epochs`, this method will take into account transitions
that occur between epochs. This could lead to wrong interpretation when working
Expand All @@ -239,9 +239,9 @@ def compute_transition_matrix(
)
_check_type(ignore_repetitions, (bool,), "ignore_repetitions")
if ignore_self is not None:
logger.warn(
"The ignore_self parameter is deprecated and will be removed in \
future versions. Please use the ignore_repetitions parameter instead."
logger.warning(
"The 'ignore_self' parameter is deprecated and will be removed in \
future versions. Please use the 'ignore_repetitions' parameter instead."
)
ignore_repetitions = ignore_self
return _compute_transition_matrix(
Expand Down Expand Up @@ -284,9 +284,9 @@ def compute_expected_transition_matrix(
)
_check_type(ignore_repetitions, (bool,), "ignore_repetitions")
if ignore_self is not None:
logger.warn(
"The ignore_self parameter is deprecated and will be removed in \
future versions. Please use the ignore_repetitions parameter instead."
logger.warning(
"The 'ignore_self' parameter is deprecated and will be removed in \
future versions. Please use the 'ignore_repetitions' parameter instead."
)
ignore_repetitions = ignore_self
return _compute_expected_transition_matrix(
Expand Down Expand Up @@ -389,7 +389,7 @@ def _check_predict_parameters(predict_parameters: dict):
"reject_by_annotation",
)
# Let the door open for custom prediction with different keys, so log
# a warning instead of raising.
# a warninginstead of raising.
for key in predict_parameters.keys():
if key not in valid_keys:
logger.warning(
Expand Down
17 changes: 17 additions & 0 deletions pycrostates/segmentation/tests/test_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,20 @@ def test_check_labels_n_clusters():
_check_labels_n_clusters(np.random.randint(0, 5, size=100).astype(float), 5)
with pytest.raises(ValueError, match=re.escape("'[6 7]' are invalid")):
_check_labels_n_clusters(np.random.randint(0, 8, size=100), 6)


def test_deprecated_ignore_self(caplog):
labels = np.random.randint(0, 5, size=100)
log = "The 'ignore_self' parameter is deprecated"

caplog.clear()
M = compute_transition_matrix(labels, 5, ignore_self=True)
assert log in caplog.text
M_ = compute_transition_matrix(labels, 5, ignore_repetitions=True)
assert_allclose(M, M_)

caplog.clear()
M = compute_expected_transition_matrix(labels, 5, ignore_self=True)
assert log in caplog.text
M_ = compute_expected_transition_matrix(labels, 5, ignore_repetitions=True)
assert_allclose(M, M_)
12 changes: 6 additions & 6 deletions pycrostates/segmentation/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def compute_transition_matrix(
)
_check_type(ignore_repetitions, (bool,), "ignore_repetitions")
if ignore_self is not None:
logger.warn(
"The ignore_self parameter is deprecated and will be removed in \
future versions. Please use the ignore_repetitions parameter instead."
logger.warning(
"The 'ignore_self' parameter is deprecated and will be removed in \
future versions. Please use the 'ignore_repetitions' parameter instead."
)
ignore_repetitions = ignore_self
return _compute_transition_matrix(
Expand Down Expand Up @@ -132,9 +132,9 @@ def compute_expected_transition_matrix(
)
_check_type(ignore_repetitions, (bool,), "ignore_repetitions")
if ignore_self is not None:
logger.warn(
"The ignore_self parameter is deprecated and will be removed in \
future versions. Please use the ignore_repetitions parameter instead."
logger.warning(
"The 'ignore_self' parameter is deprecated and will be removed in \
future versions. Please use the 'ignore_repetitions' parameter instead."
)
ignore_repetitions = ignore_self
return _compute_expected_transition_matrix(
Expand Down

0 comments on commit 8b491e9

Please sign in to comment.