Skip to content

Commit e7819e0

Browse files
committed
Applied black formatting.
1 parent 3972d97 commit e7819e0

5 files changed

Lines changed: 26 additions & 29 deletions

File tree

rtanalysis/generate_testdata.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def generate_test_df(meanRT, sdRT, meanAcc, n=100):
1919
# get random accuracy values and threshold for intended proportion
2020
accuracy_continuous = np.random.rand(n)
2121
accuracy = pd.Series(
22-
accuracy_continuous < scipy.stats.scoreatpercentile(
23-
accuracy_continuous, 100 * meanAcc))
22+
accuracy_continuous
23+
< scipy.stats.scoreatpercentile(accuracy_continuous, 100 * meanAcc)
24+
)
2425

2526
# scale the correct RTs only
2627
rt_correct = rt.mask(~accuracy)
@@ -29,8 +30,7 @@ def generate_test_df(meanRT, sdRT, meanAcc, n=100):
2930
# NB: .where() replaces values where the condition is False
3031
rt_scaled_with_inaccurate_rts = rt_scaled.where(accuracy, rt)
3132

32-
return(pd.DataFrame({'rt': rt_scaled_with_inaccurate_rts,
33-
'accuracy': accuracy}))
33+
return pd.DataFrame({"rt": rt_scaled_with_inaccurate_rts, "accuracy": accuracy})
3434

3535

3636
def scale_values(values, mean, sd):
@@ -44,4 +44,4 @@ def scale_values(values, mean, sd):
4444
values = values * (sd / np.std(values))
4545
values = (values - np.mean(values)) + mean
4646

47-
return(values)
47+
return values

rtanalysis/rtanalysis.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
# %%
1010
class RTAnalysis:
11-
"""[summary]
12-
"""
11+
"""[summary]"""
12+
1313
def __init__(self, outlier_cutoff_sd=None):
1414
"""
1515
RT analysis
@@ -35,30 +35,30 @@ def fit(self, rt, accuracy, verbose=True):
3535

3636
try:
3737
assert rt.shape[0] == accuracy.shape[0]
38-
except AssertionError:
39-
raise ValueError('rt and accuracy must be the same length!')
38+
except AssertionError as e:
39+
raise ValueError("rt and accuracy must be the same length!") from e
4040

4141
# ensure that accuracy values are boolean
42-
assert len(set(accuracy.unique()).difference([True, False])) == 0
42+
assert not set(accuracy.unique()).difference([True, False])
4343

4444
if self.outlier_cutoff_sd is not None:
4545
cutoff = rt.std() * self.outlier_cutoff_sd
4646
if verbose:
47-
print(f'outlier rejection excluded {(rt > cutoff).sum()} trials')
47+
print(f"outlier rejection excluded {(rt > cutoff).sum()} trials")
4848
rt = rt.mask(rt > cutoff)
4949

5050
self.meanacc_ = accuracy.mean()
5151
try:
5252
assert self.meanacc_ > 0
53-
except:
54-
raise ValueError('accuracy is zero')
53+
except AssertionError as e:
54+
raise ValueError("accuracy is zero") from e
5555

5656
rt = rt.mask(~accuracy)
5757
self.meanrt_ = rt.mean()
5858

5959
if verbose:
60-
print(f'mean RT: {self.meanrt_}')
61-
print(f'mean accuracy: {self.meanacc_}')
60+
print(f"mean RT: {self.meanrt_}")
61+
print(f"mean accuracy: {self.meanacc_}")
6262

6363
@staticmethod
6464
def _ensure_series_type(var):
@@ -74,4 +74,4 @@ def _ensure_series_type(var):
7474

7575
if type(var) is not pd.core.series.Series:
7676
var = pd.Series(var)
77-
return(var)
77+
return var

tests/test_1_smoketest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
def test_rtanalysis_smoke():
88
rta = RTAnalysis()
99
assert rta is not None
10-

tests/test_4_fixture.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,24 @@
1212

1313
@pytest.fixture
1414
def params():
15-
return({'meanRT': 2.1,
16-
'sdRT': 0.9,
17-
'meanAcc': 0.8})
15+
return {"meanRT": 2.1, "sdRT": 0.9, "meanAcc": 0.8}
1816

1917

2018
@pytest.fixture
2119
def simulated_data(params):
22-
return(generate_test_df(
23-
params['meanRT'], params['sdRT'], params['meanAcc']))
20+
return generate_test_df(params["meanRT"], params["sdRT"], params["meanAcc"])
2421

2522

2623
def test_rtanalysis_fit(simulated_data, params):
2724
rta = RTAnalysis()
2825
rta.fit(simulated_data.rt, simulated_data.accuracy)
29-
assert np.allclose(params['meanRT'], rta.meanrt_)
30-
assert np.allclose(params['meanAcc'], rta.meanacc_)
26+
assert np.allclose(params["meanRT"], rta.meanrt_)
27+
assert np.allclose(params["meanAcc"], rta.meanacc_)
3128

3229

3330
def test_rtanalysis_checkfail(simulated_data, params):
3431
rta = RTAnalysis()
3532
with pytest.raises(ValueError):
36-
rta.fit(simulated_data.rt,
37-
simulated_data.accuracy.loc[1:]) # omit first datapoint
33+
rta.fit(
34+
simulated_data.rt, simulated_data.accuracy.loc[1:]
35+
) # omit first datapoint

tests/test_5_parametric.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from rtanalysis.rtanalysis import RTAnalysis
1111

1212

13-
@pytest.mark.parametrize("meanRT, sdRT, meanAcc",
14-
[(1.5, 1.0, 0.9), (1500, 1000, 0.9),
15-
(1.5, 1.0, 0)])
13+
@pytest.mark.parametrize(
14+
"meanRT, sdRT, meanAcc", [(1.5, 1.0, 0.9), (1500, 1000, 0.9), (1.5, 1.0, 0)]
15+
)
1616
def test_rtanalysis_parameteric(meanRT, sdRT, meanAcc):
1717
test_df = generate_test_df(meanRT, sdRT, meanAcc)
1818
rta = RTAnalysis()

0 commit comments

Comments
 (0)