Skip to content

Commit

Permalink
Merge pull request #243 from scottclowe/mnt_supress-warnings
Browse files Browse the repository at this point in the history
MNT: Suppress warnings
  • Loading branch information
scottclowe committed Jul 13, 2021
2 parents d2d6b28 + de17ce6 commit ab895c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 6 additions & 1 deletion fissa/core.py
Expand Up @@ -1513,7 +1513,12 @@ def reformat_dict_for_matlab(orig_dict):
if getattr(self, "deltaf_result", None) is not None:
M["df_result"] = reformat_dict_for_matlab(self.deltaf_result)

savemat(fname, M)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="Creating an ndarray from ragged nested sequences",
)
savemat(fname, M)


def run_fissa(
Expand Down
15 changes: 13 additions & 2 deletions fissa/tests/base_test.py
Expand Up @@ -15,6 +15,11 @@
import unittest
from inspect import getsourcefile

try:
from collections import abc
except ImportError:
import collections as abc

import numpy as np
import pytest
from numpy.testing import (
Expand All @@ -30,9 +35,15 @@


def assert_allclose_ragged(actual, desired):
assert_equal(np.shape(actual), np.shape(desired))
assert_equal(
np.array(actual, dtype=object).shape,
np.array(desired, dtype=object).shape,
)
for desired_i, actual_i in zip(desired, actual):
if np.asarray(desired).dtype == object:
if (
getattr(desired, "dtype", None) == object
or np.asarray(desired).dtype == object
):
assert_allclose_ragged(actual_i, desired_i)
else:
assert_allclose(actual_i, desired_i)
Expand Down
12 changes: 10 additions & 2 deletions fissa/tests/test_core.py
Expand Up @@ -1040,7 +1040,11 @@ def test_calcdeltaf_cache(self):
def test_calcdeltaf_notrawf0(self):
exp = core.Experiment(self.images_dir, self.roi_zip_path, verbosity=4)
exp.separate()
exp.calc_deltaf(self.fs, use_raw_f0=False)
# Ignore division by zero, which is likely to occur now and something
# we want to alert the user to.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="divide by zero")
exp.calc_deltaf(self.fs, use_raw_f0=False)
# We did not use this setting to generate the expected values, so can't
# compare the output against the target.
self.compare_output(exp, compare_deltaf=False)
Expand All @@ -1062,7 +1066,11 @@ def test_calcdeltaf_notacrosstrials(self):
def test_calcdeltaf_notrawf0_notacrosstrials(self):
exp = core.Experiment(self.images_dir, self.roi_zip_path, verbosity=4)
exp.separate()
exp.calc_deltaf(self.fs, use_raw_f0=False, across_trials=False)
# Ignore division by zero, which is likely to occur now and something
# we want to alert the user to.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="divide by zero")
exp.calc_deltaf(self.fs, use_raw_f0=False, across_trials=False)
# We did not use this setting to generate the expected values, so can't
# compare the output against the target.
self.compare_output(exp, compare_deltaf=False)
Expand Down

0 comments on commit ab895c3

Please sign in to comment.