Skip to content

Commit

Permalink
adds initial sphinx documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
drbenvincent committed Nov 14, 2022
1 parent 5ba811b commit 1caf199
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 42 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*.egg-info
*.DS_Store
__pycache__
_build
.ipynb_checkpoints
*_checkpoints
*.DS_Store
*.egg-info
build/
dist/
docs/_build/
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
9 changes: 9 additions & 0 deletions docs/api_plot_utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:mod:`causalpy.plot_utils`
==========================

.. toctree::
:maxdepth: 1

.. automodule:: causalpy.plot_utils
:members:
:undoc-members:
9 changes: 9 additions & 0 deletions docs/api_pymc_experiments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:mod:`causalpy.pymc_experiments`
================================

.. toctree::
:maxdepth: 1

.. automodule:: causalpy.pymc_experiments
:members:
:undoc-members:
9 changes: 9 additions & 0 deletions docs/api_pymc_models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:mod:`causalpy.pymc_models`
===========================

.. toctree::
:maxdepth: 1

.. automodule:: causalpy.pymc_models
:members:
:undoc-members:
9 changes: 9 additions & 0 deletions docs/api_skl_experiments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:mod:`causalpy.skl_experiments`
===============================

.. toctree::
:maxdepth: 1

.. automodule:: causalpy.skl_experiments
:members:
:undoc-members:
9 changes: 9 additions & 0 deletions docs/api_skl_models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:mod:`causalpy.skl_models`
==========================

.. toctree::
:maxdepth: 1

.. automodule:: causalpy.skl_models
:members:
:undoc-members:
72 changes: 72 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html


# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys

sys.path.insert(0, os.path.abspath("../mypackage"))


# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "CausalPy"
copyright = "2022, Benjamin T. Vincent"
author = "Benjamin T. Vincent"
release = "0.0.1"


# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.mathjax",
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"nbsphinx",
"myst_parser",
]

source_suffix = [".rst", ".md"]
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# MyST options for working with markdown files. Info about extensions here https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=math#admonition-directives
myst_enable_extensions = ["dollarmath", "amsmath", "colon_fence", "linkify"]

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
# TODO: version seems not to be displayed despite setting this to True
html_theme_options = {
"display_version": True,
}

# -- Options for autodoc ----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration

# Automatically extract typehints when specified and place them in
# descriptions of the relevant function/method.
autodoc_typehints = "description"

# Don't show class signature with the class' name.
autodoc_class_signature = "separated"

# Add "Edit on Github" link. Replaces "view page source" ----------------------
html_context = {
"display_github": True, # Integrate GitHub
"github_user": "pymc-labs", # Username
"github_repo": "CausalPy", # Repo name
"github_version": "master", # Version
"conf_py_path": "/docs/", # Path in the checkout to the docs root
}
41 changes: 41 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. CausalPy documentation master file, created by
sphinx-quickstart on Mon Nov 14 18:28:13 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
CausalPy - Causal inference in quasi-experimental settings
==========================================================

A Python package focussing on causal inference in quasi-experimental settings. The package allows for sophisticated Bayesian model fitting methods to be used in addition to traditional OLS.

.. toctree::
:maxdepth: 2
:caption: Contents:

Documentation outline
=====================

.. toctree::
:caption: Examples
:titlesonly:

notebooks/skl_demos.ipynb
notebooks/pymc_demos.ipynb

.. toctree::
:caption: API Reference
:titlesonly:

api_skl_experiments
api_skl_models
api_pymc_experiments
api_pymc_models
api_plot_utils


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
18 changes: 9 additions & 9 deletions notebooks/pymc_demos.ipynb → docs/notebooks/pymc_demos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"outputs": [],
"source": [
"sc_data_path = (\n",
" pathlib.Path.cwd().parents[0] / \"causalpy\" / \"data\" / \"synthetic_control.csv\"\n",
" pathlib.Path.cwd().parents[1] / \"causalpy\" / \"data\" / \"synthetic_control.csv\"\n",
")\n",
"df = pd.read_csv(sc_data_path)\n",
"treatment_time = 70"
Expand Down Expand Up @@ -360,7 +360,7 @@
"\n",
"if export_images:\n",
" plt.savefig(\n",
" pathlib.Path.cwd().parents[0] / \"img\" / \"synthetic_control_pymc.svg\",\n",
" pathlib.Path.cwd().parents[1] / \"img\" / \"synthetic_control_pymc.svg\",\n",
" bbox_inches=\"tight\",\n",
" format=\"svg\",\n",
" )"
Expand All @@ -379,7 +379,7 @@
"metadata": {},
"outputs": [],
"source": [
"its_data_path = pathlib.Path.cwd().parents[0] / \"causalpy\" / \"data\" / \"its.csv\"\n",
"its_data_path = pathlib.Path.cwd().parents[1] / \"causalpy\" / \"data\" / \"its.csv\"\n",
"df = pd.read_csv(its_data_path, parse_dates=[\"date\"])\n",
"df.set_index(\"date\", inplace=True)\n",
"treatment_time = pd.to_datetime(\"2017-01-01\")"
Expand Down Expand Up @@ -676,7 +676,7 @@
"\n",
"if export_images:\n",
" plt.savefig(\n",
" pathlib.Path.cwd().parents[0] / \"img\" / \"interrupted_time_series_pymc.svg\",\n",
" pathlib.Path.cwd().parents[1] / \"img\" / \"interrupted_time_series_pymc.svg\",\n",
" bbox_inches=\"tight\",\n",
" format=\"svg\",\n",
" )"
Expand All @@ -695,7 +695,7 @@
"metadata": {},
"outputs": [],
"source": [
"did_data_path = pathlib.Path.cwd().parents[0] / \"causalpy\" / \"data\" / \"did.csv\"\n",
"did_data_path = pathlib.Path.cwd().parents[1] / \"causalpy\" / \"data\" / \"did.csv\"\n",
"\n",
"df = pd.read_csv(did_data_path)"
]
Expand Down Expand Up @@ -989,7 +989,7 @@
"\n",
"if export_images:\n",
" plt.savefig(\n",
" pathlib.Path.cwd().parents[0] / \"img\" / \"difference_in_differences_pymc.svg\",\n",
" pathlib.Path.cwd().parents[1] / \"img\" / \"difference_in_differences_pymc.svg\",\n",
" bbox_inches=\"tight\",\n",
" format=\"svg\",\n",
" )"
Expand All @@ -1009,7 +1009,7 @@
"outputs": [],
"source": [
"rd_data_path = (\n",
" pathlib.Path.cwd().parents[0] / \"causalpy\" / \"data\" / \"regression_discontinuity.csv\"\n",
" pathlib.Path.cwd().parents[1] / \"causalpy\" / \"data\" / \"regression_discontinuity.csv\"\n",
")\n",
"df = pd.read_csv(rd_data_path)"
]
Expand Down Expand Up @@ -1304,7 +1304,7 @@
"\n",
"if export_images:\n",
" plt.savefig(\n",
" pathlib.Path.cwd().parents[0] / \"img\" / \"regression_discontinuity_pymc.svg\",\n",
" pathlib.Path.cwd().parents[1] / \"img\" / \"regression_discontinuity_pymc.svg\",\n",
" bbox_inches=\"tight\",\n",
" format=\"svg\",\n",
" )"
Expand All @@ -1323,7 +1323,7 @@
"metadata": {},
"outputs": [],
"source": [
"rd_data_path = pathlib.Path.cwd().parents[0] / \"causalpy\" / \"data\" / \"drinking.csv\"\n",
"rd_data_path = pathlib.Path.cwd().parents[1] / \"causalpy\" / \"data\" / \"drinking.csv\"\n",
"df = (\n",
" pd.read_csv(rd_data_path)[[\"agecell\", \"all\", \"mva\", \"suicide\"]]\n",
" .rename(columns={\"agecell\": \"age\"})\n",
Expand Down
Loading

0 comments on commit 1caf199

Please sign in to comment.