Skip to content

Commit 876633d

Browse files
Merge pull request #90 from Quantmetry/chp_test_docstrings_examples
add test on docstrings examples
2 parents 5da0a9b + 5624bdd commit 876633d

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ jobs:
3535
- name: Test with pytest
3636
run: |
3737
conda install pytest
38-
pytest
39-
echo you should uncomment pytest and delete this line
38+
make coverage
39+
- name: Test docstrings examples
40+
run: make doctest
4041
- name: typing with mypy
4142
run: |
4243
mypy qolmat

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
coverage:
2+
pytest --cov-branch --cov=qolmat --cov-report=xml
3+
4+
doctest:
5+
pytest --doctest-modules --pyargs qolmat
6+
7+
clean:
8+
rm -rf .mypy_cache .pytest_cache .coverage*
9+
rm -rf **__pycache__

qolmat/imputations/em_sampler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ class VARpEM(EM):
668668
>>> from qolmat.imputations.em_sampler import VARpEM
669669
>>> imputer = VARpEM(method="sample")
670670
>>> X = pd.DataFrame(data=[[1, 1, 1, 1],
671-
>>> [np.nan, np.nan, 3, 2],
672-
>>> [1, 2, 2, 1], [2, 2, 2, 2]],
673-
>>> columns=["var1", "var2", "var3", "var4"])
674-
>>> imputer.fit_transform(X)
671+
... [np.nan, np.nan, 3, 2],
672+
... [1, 2, 2, 1], [2, 2, 2, 2]],
673+
... columns=["var1", "var2", "var3", "var4"])
674+
>>> imputer.fit_transform(X) # doctest: +SKIP
675675
"""
676676

677677
def __init__(

qolmat/imputations/imputers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ class ImputerResiduals(_Imputer):
11171117
TODO review/remake this exemple
11181118
>>> import numpy as np
11191119
>>> import pandas as pd
1120-
>>> from qolmat.imputations.models import ImputeOnResiduals
1120+
>>> from qolmat.imputations.imputers import ImputerResiduals
11211121
>>> df = pd.DataFrame(index=pd.date_range('2015-01-01','2020-01-01'))
11221122
>>> mean = 5
11231123
>>> offset = 10
@@ -1130,8 +1130,8 @@ class ImputerResiduals(_Imputer):
11301130
>>> np.random.seed(100)
11311131
>>> mask = np.random.choice([True, False], size=df.shape)
11321132
>>> df = df.mask(mask)
1133-
>>> imputor = ImputeOnResiduals(period=365, model="additive")
1134-
>>> imputor.fit_transform(df)
1133+
>>> imputor.fit_transform(df) # doctest: +SKIP
1134+
>>> imputor = ImputerResiduals(period=365, model_tsa="additive")
11351135
"""
11361136

11371137
def __init__(
@@ -1353,10 +1353,10 @@ class ImputerMICE(_Imputer):
13531353
... columns=["var1", "var2", "var3", "var4"])
13541354
>>> imputer.fit_transform(df)
13551355
var1 var2 var3 var4
1356-
0 1.0 1.0 1.0 1.0
1357-
1 1.0 2.0 2.0 5.0
1358-
2 1.0 2.0 2.0 5.0
1359-
3 2.0 2.0 2.0 2.0
1356+
0 1.00 1.00 1.00 1.00
1357+
1 1.51 1.99 1.99 3.55
1358+
2 1.00 2.00 2.00 5.00
1359+
3 2.00 2.00 2.00 2.00
13601360
"""
13611361

13621362
def __init__(
@@ -1470,18 +1470,18 @@ class ImputerRegressor(_Imputer):
14701470
>>> import pandas as pd
14711471
>>> from qolmat.imputations import imputers
14721472
>>> from sklearn.ensemble import ExtraTreesRegressor
1473-
>>> imputer = imputers.ImputerRegressor(model=ExtraTreesRegressor())
1473+
>>> imputer = imputers.ImputerRegressor(estimator=ExtraTreesRegressor())
14741474
>>> df = pd.DataFrame(data=[[1, 1, 1, 1],
14751475
... [np.nan, np.nan, np.nan, np.nan],
14761476
... [1, 2, 2, 5],
14771477
... [2, 2, 2, 2]],
14781478
... columns=["var1", "var2", "var3", "var4"])
14791479
>>> imputer.fit_transform(df)
1480-
var1 var2 var3 var4
1481-
0 1.000000 1.000000 1.000000 1.000000
1482-
1 1.333333 1.666667 1.666667 2.666667
1483-
2 1.000000 2.000000 2.000000 5.000000
1484-
3 2.000000 2.000000 2.000000 2.000000
1480+
var1 var2 var3 var4
1481+
0 1.0 1.0 1.0 1.0
1482+
1 1.0 2.0 2.0 2.0
1483+
2 1.0 2.0 2.0 5.0
1484+
3 2.0 2.0 2.0 2.0
14851485
"""
14861486

14871487
def __init__(

qolmat/imputations/imputers_pytorch.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,10 @@ def build_autoencoder(
471471
472472
Examples
473473
--------
474-
>>> encoder, decoder = build_autoencoder(
475-
input_dim=10,
476-
latent_dim=4,
477-
list_num_neurons=[32, 64, 128],
478-
output_dim=252
479-
)
474+
>>> encoder, decoder = build_autoencoder(input_dim=10,
475+
... latent_dim=4,
476+
... list_num_neurons=[32, 64, 128],
477+
... output_dim=252)
480478
>>> print(encoder)
481479
Sequential(
482480
(0): Linear(in_features=10, out_features=128, bias=True)

qolmat/imputations/softimpute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class SoftImpute(BaseEstimator, TransformerMixin):
4848
>>> X = np.array([[1, 2, np.nan, 4], [1, 5, 3, np.nan], [4, 2, 3, 2], [1, 1, 5, 4]])
4949
>>> X_imputed = SoftImpute().fit_transform(X)
5050
>>> print(X_imputed)
51+
[[ 1. 2. 4.7369014 4. ]
52+
[ 1. 5. 3. -0.52477073]
53+
[ 4. 2. 3. 2. ]
54+
[ 1. 1. 5. 4. ]]
5155
"""
5256

5357
def __init__(

0 commit comments

Comments
 (0)