Skip to content

Commit 0730870

Browse files
authored
Merge pull request #7 from ZviBaratz/suggestions
Suggestions
2 parents bf7e548 + e7819e0 commit 0730870

12 files changed

Lines changed: 273 additions & 218 deletions

.github/workflows/python-app.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,30 @@ name: Python application
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python 3.8
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: 3.8
23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install flake8 pytest numpy pandas scipy
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28-
- name: Lint with flake8
29-
run: |
30-
# stop the build if there are Python syntax errors or undefined names
31-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34-
- name: Test with pytest
35-
run: |
36-
python -m pytest
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.8
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.8
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
- name: Lint with flake8
27+
run: |
28+
# stop the build if there are Python syntax errors or undefined names
29+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
30+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
31+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
32+
- name: Test with pytest
33+
run: |
34+
python -m pytest

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
__pycache__
1+
# Virtual environment directory
2+
venv
3+
.venv
4+
5+
# Cache directories and byte-code files
6+
*.py[cod]
7+
__pycache__/
8+
.pytest_cache/
9+
.ipynb_checkpoints
210
.coverage
11+
12+
# Editor directories and files
13+
.idea
14+
.vscode
15+
.vs
16+
17+
# Local solutions directory
18+
solutions

README.md

Lines changed: 193 additions & 152 deletions
Large diffs are not rendered by default.

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
coverage
2+
flake8
3+
numpy
4+
pandas
5+
pytest
6+
pytest-cov
7+
scipy

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""test suite for rtanalysis
22
"""
3-
43
import pytest
54
from rtanalysis.rtanalysis import RTAnalysis
65

6+
77
def test_rtanalysis_smoke():
88
rta = RTAnalysis()
99
assert rta is not None
10-

tests/test_2_fit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
- in this test, we will create a simulated dataset and fit
44
it, ensuring that the answers are correct
55
"""
6-
76
import numpy as np
8-
from rtanalysis.rtanalysis import RTAnalysis
97
from rtanalysis.generate_testdata import generate_test_df
8+
from rtanalysis.rtanalysis import RTAnalysis
109

1110

1211
def test_rtanalysis_fit():

tests/test_3_type_fail.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
test for rtanalysis
33
- in this test, we will ensure that the function raises a ValueError
44
"""
5-
65
import pytest
7-
from rtanalysis.rtanalysis import RTAnalysis
86
from rtanalysis.generate_testdata import generate_test_df
7+
from rtanalysis.rtanalysis import RTAnalysis
98

109

1110
# This xfail decorator tells pytest to run the test

tests/test_3_type_success.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
test for rtanalysis
33
- in this test, we will ensure that the function raises a ValueError
44
"""
5-
65
import pytest
7-
from rtanalysis.rtanalysis import RTAnalysis
86
from rtanalysis.generate_testdata import generate_test_df
7+
from rtanalysis.rtanalysis import RTAnalysis
98

109

1110
def test_dataframe_error_with_raises():

0 commit comments

Comments
 (0)