Skip to content

Commit 6a7ca58

Browse files
committed
add tests for data conversions
1 parent 673adee commit 6a7ca58

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Tests for the fooof.data.conversions."""
2+
3+
from copy import deepcopy
4+
5+
import numpy as np
6+
7+
from fooof.core.modutils import safe_import
8+
pd = safe_import('pandas')
9+
10+
from fooof.data.conversions import *
11+
12+
###################################################################################################
13+
###################################################################################################
14+
15+
def test_model_to_dict(tresults, tbands):
16+
17+
out = model_to_dict(tresults, peak_org=1)
18+
assert isinstance(out, dict)
19+
assert 'cf_0' in out
20+
assert out['cf_0'] == tresults.peak_params[0, 0]
21+
assert not 'cf_1' in out
22+
23+
out = model_to_dict(tresults, peak_org=2)
24+
assert 'cf_0' in out
25+
assert 'cf_1' in out
26+
assert out['cf_1'] == tresults.peak_params[1, 0]
27+
28+
out = model_to_dict(tresults, peak_org=3)
29+
assert 'cf_2' in out
30+
assert np.isnan(out['cf_2'])
31+
32+
out = model_to_dataframe(tresults, peak_org=tbands)
33+
assert 'alpha_cf' in out
34+
35+
def test_model_to_dataframe(tresults, tbands, skip_if_no_pandas):
36+
37+
for peak_org in [1, 2, 3]:
38+
out = model_to_dataframe(tresults, peak_org=peak_org)
39+
assert isinstance(out, pd.Series)
40+
41+
out = model_to_dataframe(tresults, peak_org=tbands)
42+
assert isinstance(out, pd.Series)
43+
44+
def test_group_to_dataframe(tresults, tbands, skip_if_no_pandas):
45+
46+
fit_results = [deepcopy(tresults), deepcopy(tresults), deepcopy(tresults)]
47+
48+
for peak_org in [1, 2, 3]:
49+
out = group_to_dataframe(fit_results, peak_org=peak_org)
50+
assert isinstance(out, pd.DataFrame)
51+
52+
out = group_to_dataframe(fit_results, peak_org=tbands)
53+
assert isinstance(out, pd.DataFrame)

0 commit comments

Comments
 (0)