Skip to content

Commit 9b8259b

Browse files
authored
Convert docstrings to numpydoc convention. (#72)
* Start converting docstrings to numpydoc convention. * Mark a few more to change. * Add linting job. * Docstrings! * Fix kwargs. * Update core.py * Some docstrings for tests. * More work. * More docstrings. * More docstrings. * Fix up examples. * Fix up docstrings more.
1 parent f009e43 commit 9b8259b

25 files changed

+906
-598
lines changed

.github/workflows/testing.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,26 @@ jobs:
5959
- name: 'Upload coverage to CodeCov'
6060
uses: codecov/codecov-action@v1
6161
if: success()
62+
63+
flake8-lint:
64+
runs-on: ubuntu-latest
65+
name: Lint with flake8
66+
steps:
67+
- name: Check out source repository
68+
uses: actions/checkout@v2
69+
70+
- name: Set up Python environment
71+
uses: actions/setup-python@v2
72+
with:
73+
python-version: "3.7"
74+
75+
- name: "Install the package"
76+
shell: bash {0}
77+
run: |
78+
python -m pip install --progress-bar off --upgrade pip setuptools wheel
79+
python -m pip install -e .[tests]
80+
81+
- name: "Run flake8"
82+
shell: bash {0}
83+
run: |
84+
flake8 pymare

docs/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ help:
1515
clean:
1616
rm -r _build generated auto_examples
1717

18+
html-noplot:
19+
$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
20+
@echo
21+
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
22+
1823
.PHONY: help clean Makefile
1924

2025
# Catch-all target: route all unknown targets to Sphinx using the new

docs/api.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ API
4444
estimators.SampleSizeBasedLikelihoodEstimator
4545
estimators.StanMetaRegression
4646
estimators.Hedges
47-
estimators.Stouffers
48-
estimators.Fishers
47+
estimators.StoufferCombinationTest
48+
estimators.FisherCombinationTest
49+
estimators.estimators.BaseEstimator
4950

5051

5152
.. _api_results_ref:

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@
191191

192192
def setup(app):
193193
"""From https://github.com/rtfd/sphinx_rtd_theme/issues/117."""
194-
app.add_stylesheet("theme_overrides.css")
195-
app.add_stylesheet("pymare.css")
194+
app.add_css_file("theme_overrides.css")
195+
app.add_css_file("pymare.css")
196196
app.connect("autodoc-process-docstring", generate_example_rst)
197197
# Fix to https://github.com/sphinx-doc/sphinx/issues/7420
198198
# from https://github.com/life4/deal/commit/7f33cbc595ed31519cefdfaaf6f415dada5acd94

examples/01_basic_io/plot_create_dataset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
Creating a dataset
88
===================
99
10-
In PyMARE, operations are performed on :class:`pymare.core.Dataset` objects.
10+
In PyMARE, operations are performed on :class:`~pymare.core.Dataset` objects.
1111
Datasets are very lightweight objects that store the data used for
1212
meta-analyses, including study-level estimates (y), variances (v),
1313
predictors (X), and sample sizes (n).
1414
"""
15+
from pprint import pprint
16+
1517
###############################################################################
1618
# Start with the necessary imports
1719
# --------------------------------
1820
import pandas as pd
19-
from pprint import pprint
2021

2122
from pymare import core
2223

examples/02_meta-analysis/plot_meta-analysis_walkthrough.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def var_to_ci(y, v, n):
113113
###############################################################################
114114
# Create a Dataset object containing the data
115115
# --------------------------------------------
116-
dset = pymare.Dataset(y=y, X=None, v=v, n=n, add_intercept=True)
116+
dset = pymare.core.Dataset(y=y, X=None, v=v, n=n, add_intercept=True)
117117

118118
# Here is a dictionary to house results across models
119119
results = {}
@@ -123,8 +123,8 @@ def var_to_ci(y, v, n):
123123
# -----------------------------------------------------------------------------
124124
# When you have ``z`` or ``p``:
125125
#
126-
# - :class:`pymare.estimators.Stouffers`
127-
# - :class:`pymare.estimators.Fishers`
126+
# - :class:`pymare.estimators.StoufferCombinationTest`
127+
# - :class:`pymare.estimators.FisherCombinationTest`
128128
#
129129
# When you have ``y`` and ``v`` and don't want to estimate between-study variance:
130130
#
@@ -149,7 +149,7 @@ def var_to_ci(y, v, n):
149149
# `````````````````````````````````````````````````````````````````````````````
150150
# The two combination models in PyMARE are Stouffer's and Fisher's Tests.
151151
#
152-
# Notice that these models don't use :class:`pymare.core.Dataset` objects.
152+
# Notice that these models don't use :class:`~pymare.core.Dataset` objects.
153153
stouff = pymare.estimators.StoufferCombinationTest()
154154
stouff.fit(z[:, None])
155155
print("Stouffers")

pymare/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""PyMARE: Python Meta-Analysis & Regression Engine"""
1+
"""PyMARE: Python Meta-Analysis & Regression Engine."""
22
from .core import Dataset, meta_regression
33
from .effectsize import OneSampleEffectSizeConverter, TwoSampleEffectSizeConverter
44

@@ -12,3 +12,4 @@
1212
from . import _version
1313

1414
__version__ = _version.get_versions()["version"]
15+
del _version

pymare/core.py

Lines changed: 92 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,39 @@
1919
class Dataset:
2020
"""Container for input data and arguments to estimators.
2121
22-
Args:
23-
y (array-like, str): 1d array of study-level estimates with length K,
24-
or the name of the column in data containing the y values.
25-
v (array-like, str, optional): 1d array of study-level variances with
26-
length K, or the name of the column in data containing v values.
27-
X (array-like, list, optional): 1d or 2d array containing study-level
28-
predictors (dimensions K x P), or a list of strings giving the
29-
names of the columns in data containing the X values.
30-
n (array-like, str, optional): 1d array of study-level sample sizes
31-
(length K), or the name of the corresponding column in data.
32-
data (pandas.DataFrame, optional): A pandas DataFrame containing y, v,
33-
X, and/or n values. By default, columns are expected to have the
34-
same names as arguments (e.g., the y values will be expected in the
35-
'y' column). This can be modified by passing strings giving column
36-
names to any of the y, v, X, or n arguments.
37-
X_names ([str], optional): List of length P containing the names of the
38-
predictors. Ignored if data is provided (use X to specify columns).
39-
add_intercept (bool, optional): If True, an intercept column is
40-
automatically added to the predictor matrix. If False, the
41-
predictors matrix is passed as-is to estimators.
22+
Parameters
23+
----------
24+
y : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
25+
1d array of study-level estimates with length K, or the name of the column in data
26+
containing the y values.
27+
Default is None.
28+
v : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
29+
1d array of study-level variances with length K, or the name of the column in data
30+
containing v values.
31+
Default is None.
32+
X : None or :obj:`numpy.ndarray` of shape (K,[P]) or :obj:`list` of :obj:`str`, optional
33+
1d or 2d array containing study-level predictors (dimensions K x P),
34+
or a list of strings giving the names of the columns in data containing the X values.
35+
Default is None.
36+
n : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
37+
1d array of study-level sample sizes (length K), or the name of the corresponding column
38+
in ``data``.
39+
Default is None.
40+
data : None or :obj:`pandas.DataFrame`, optional
41+
A pandas DataFrame containing y, v, X, and/or n values.
42+
By default, columns are expected to have the same names as arguments
43+
(e.g., the y values will be expected in the 'y' column).
44+
This can be modified by passing strings giving column names to any of the ``y``, ``v``,
45+
``X``, or ``n`` arguments.
46+
Default is None.
47+
X_names : None or :obj:`list` of :obj:`str`, optional
48+
List of length P containing the names of the predictors.
49+
Ignored if ``data`` is provided (use ``X`` to specify columns).
50+
Default is None.
51+
add_intercept : :obj:`bool`, optional
52+
If True, an intercept column is automatically added to the predictor matrix.
53+
If False, the predictors matrix is passed as-is to estimators.
54+
Default is True.
4255
"""
4356

4457
def __init__(
@@ -94,47 +107,65 @@ def meta_regression(
94107
alpha=0.05,
95108
**kwargs,
96109
):
97-
"""Fits the standard meta-regression/meta-analysis model to provided data.
98-
99-
Args:
100-
y (array-like, str): 1d array of study-level estimates with length K,
101-
or the name of the column in data containing the y values.
102-
v (array-like, str, optional): 1d array of study-level variances with
103-
length K, or the name of the column in data containing v values.
104-
X (array-like, list, optional): 1d or 2d array containing study-level
105-
predictors (dimensions K x P), or a list of strings giving the
106-
names of the columns in data containing the X values.
107-
n (array-like, str, optional): 1d array of study-level sample sizes
108-
(length K), or the name of the corresponding column in data.
109-
data (pandas.DataFrame, pymare.Dataset, optional): If a Dataset
110-
instance is passed, the y, v, X, n and associated arguments are
111-
ignored, and data is passed directly to the selected estimator.
112-
If a pandas DataFrame, y, v, X and/or n values are taken from the
113-
DF columns. By default, columns are expected to have the same names
114-
as arguments (e.g., the y values will be expected in the 'y'
115-
column). This can be modified by passing strings giving column
116-
names to any of the y, v, X, or n arguments.
117-
X_names ([str], optional): List of length P containing the names of the
118-
predictors. Ignored if data is provided (use X to specify columns).
119-
add_intercept (bool, optional): If True, an intercept column is
120-
automatically added to the predictor matrix. If False, the
121-
predictors matrix is passed as-is to estimators.
122-
method (str, optional): Name of estimation method. Defaults to 'ML'.
123-
Supported estimators include:
124-
* 'ML': Maximum-likelihood estimator
125-
* 'REML': Restricted maximum-likelihood estimator
126-
* 'DL': DerSimonian-Laird estimator
127-
* 'HE': Hedges estimator
128-
* 'WLS' or 'FE': Weighted least squares (fixed effects only)
129-
* 'Stan': Full Bayesian MCMC estimation via Stan
130-
ci_method (str, optional): Estimation method to use when computing
131-
uncertainty estimates. Currently only 'QP' is supported. Defaults
132-
to 'QP'. Ignored if method == 'Stan'.
133-
alpha (float, optional): Desired alpha level (CIs will have 1 - alpha
134-
coverage). Defaults to 0.05.
135-
kwargs: Optional keyword arguments to pass onto the chosen estimator.
136-
137-
Returns:
110+
"""Fit the standard meta-regression/meta-analysis model to provided data.
111+
112+
Parameters
113+
----------
114+
y : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
115+
1d array of study-level estimates with length K, or the name of the column in data
116+
containing the y values.
117+
Default is None.
118+
v : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
119+
1d array of study-level variances with length K, or the name of the column in data
120+
containing v values.
121+
Default is None.
122+
X : None or :obj:`numpy.ndarray` of shape (K,[P]) or :obj:`list` of :obj:`str`, optional
123+
1d or 2d array containing study-level predictors (dimensions K x P),
124+
or a list of strings giving the names of the columns in data containing the X values.
125+
Default is None.
126+
n : None or :obj:`numpy.ndarray` of shape (K,) or :obj:`str`, optional
127+
1d array of study-level sample sizes (length K), or the name of the corresponding column
128+
in ``data``.
129+
Default is None.
130+
data : None or :obj:`pandas.DataFrame` or :obj:`~pymare.core.Dataset`, optional
131+
If a Dataset instance is passed, the y, v, X, n and associated arguments are ignored,
132+
and data is passed directly to the selected estimator.
133+
If a pandas DataFrame, y, v, X and/or n values are taken from the DF columns.
134+
By default, columns are expected to have the same names as arguments
135+
(e.g., the y values will be expected in the 'y' column).
136+
This can be modified by passing strings giving column names to any of the y, v, X, or n
137+
arguments.
138+
X_names : None or :obj:`list` of :obj:`str`, optional
139+
List of length P containing the names of the predictors.
140+
Ignored if ``data`` is provided (use ``X`` to specify columns).
141+
Default is None.
142+
add_intercept : :obj:`bool`, optional
143+
If True, an intercept column is automatically added to the predictor matrix.
144+
If False, the predictors matrix is passed as-is to estimators.
145+
Default is True.
146+
method : {"ML", "REML", "DL", "HE", "WLS", "FE", "Stan"}, optional
147+
Name of estimation method. Default is 'ML'.
148+
Supported estimators include:
149+
150+
- 'ML': Maximum-likelihood estimator
151+
- 'REML': Restricted maximum-likelihood estimator
152+
- 'DL': DerSimonian-Laird estimator
153+
- 'HE': Hedges estimator
154+
- 'WLS' or 'FE': Weighted least squares (fixed effects only)
155+
- 'Stan': Full Bayesian MCMC estimation via Stan
156+
ci_method : {"QP"}, optional
157+
Estimation method to use when computing uncertainty estimates.
158+
Currently only 'QP' is supported. Default is 'QP'.
159+
Ignored if ``method == 'Stan'``.
160+
alpha : :obj:`float`, optional
161+
Desired alpha level (CIs will have 1 - alpha coverage). Default is 0.05.
162+
**kwargs
163+
Optional keyword arguments to pass onto the chosen estimator.
164+
165+
Returns
166+
-------
167+
:obj:`~pymare.results.MetaRegressionResults` or \
168+
:obj:`~pymare.results.BayesianMetaRegressionResults`
138169
A MetaRegressionResults or BayesianMetaRegressionResults instance,
139170
depending on the specified method ('Stan' will return the latter; all
140171
other methods return the former).

pymare/effectsize/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Tools for converting between effect-size measures."""
12
from .base import (
23
OneSampleEffectSizeConverter,
34
TwoSampleEffectSizeConverter,

0 commit comments

Comments
 (0)