Skip to content

DOC/BLD: Update notebook documentation system - #2816

Merged
josef-pkt merged 16 commits into
statsmodels:masterfrom
TomAugspurger:nb-simple
Feb 18, 2016
Merged

josef-pkt merged 16 commits into
statsmodels:masterfrom
TomAugspurger:nb-simple

Conversation

@TomAugspurger

Copy link
Copy Markdown
Contributor

Closes #2813

Still a WIP for now. I'll eventually replace nbgenerate.py with mine and work it into the doc build process. Also a few compatibility issues in the notebooks that I'll fix up.

I'll see if I can upload the output somewhere. It looks pretty good. I'm using nbconvert==4.1.0 and nbformat==4.0.1. I'll put those in the setup.py as a extra_requires.

edit (Josef):

see below for comments where the the structure has changed

  • numpydoc is doc build dependency, not included anymore
  • code in rst files is now executed
  • for reference: links to notebooks currently require html see 10d3ed5

@TomAugspurger

Copy link
Copy Markdown
Contributor Author

OK, all of the notebooks except for discrete_choice_example and discrete_choice_overview are running. Those are failing due to #2817

The diff on github is not pretty thanks to all the notebooks. The majority of that is due to the update to notebook version 4. If you diff f598771 to e748d04 the changes are pretty minor. I tried to split out actual code changes into separate commits as well.

Next up I'll integrate the new build script into the docs' Makefile and Makefile.bat.

@josef-pkt

Copy link
Copy Markdown
Member

One possibility to rescue some more informative changesets is to export and commit the python version. I would like to add this as future commit guideline for notebooks.
Some blogs recommended even git pre-commit hooks, but in my old experience those don't work on Windows (I haven't tried in many years).

I expected already that we need at least one uninformative changeset in the notebook upgrades.

@TomAugspurger TomAugspurger changed the title WIP/DOC/BLD: Update notebook documentation system DOC/BLD: Update notebook documentation system Feb 16, 2016
@TomAugspurger

Copy link
Copy Markdown
Contributor Author

I removed my "WIP" tag a bit early. AFAIK, it should work on python 3, but I'm still working on python2 kernels. I'll ping when I think it's ready for review / merge.

@josef-pkt

Copy link
Copy Markdown
Member

Is it possible to get the website/doc header on the notebook example pages, or is this to much extra complication? or you think it's better this way?

e.g.
http://www.statsmodels.org/dev/examples/notebooks/generated/glm_formula.html

@TomAugspurger

Copy link
Copy Markdown
Contributor Author

I don't think that will be difficult at all. nbconvert does support it. I believe it's just a matter of having a properly structured Jinja template. I'll try with the templates in docs/themes tonight, and hope that it works.

Using nbformat and nbconvert instead of our own custom
tools.

COMPAT: use io.open and UTF-8 encoding
@TomAugspurger

Copy link
Copy Markdown
Contributor Author

Going to have to push the HTML styling till tomorrow (and possibly next week if I don't get it tomorrow).

Anyway, I think we have a cross-platform, python 2/3 compatible doc build now. The only caveat is that you need the development version of nbconvert to do python2 builds (pip install -U git+https://github.com/jupyter/nbconvert). The currently released version doesn't handle the kernel argument, and I used python3 to convert the notebooks to version 4.

The biggest change from the last version is replacing almost all the .. code-block:: python sections in the .rst docs with actual .. ipython:: python blocks, which means the code actually gets executed. The only one I couldn't change is duration.rst which for whatever reason messed the execution up in index.rst. I'll upload those tomorrow.

Going forward, what will it take to get this merged? To make review easier, I can split the very first commit TomAugspurger@d423f3f, which converts all the notebooks to version 4, off on its own. Every other commit is tiny compared to that.
I also want to get this process into Travis, so that docs are built automatically, but that will take a bit more time I think.

@josef-pkt

Copy link
Copy Markdown
Member

splitting out the format conversion, or saving/exporting the python version before and at the end of the PR would make the changes easier to see.

However, I thought of just merging whenever you say so.
The only really reviewable change is in nbgenerate2.py and there I assume you know much better what's going on than I.

If there is a useful diff for the changes that you made to the notebooks, then that would be helpful. But, I think we have to review the documentation and notebooks anyway.

I'm just glad you did this and managed to get it to work.

Things that need adjustments, if there are any, or extension like CI integration can be in followups.
AFAICS from the incomplete change list on github, you haven't added the updating or deleting of the included numpydoc. A separate PR would make a better git history, I think.

doc the docs

ignore datasets
DOCS: Change build process

numpydoc was behind, remove that and pip install it instead.
Add a build step to copy the generated notebooks to build/html
BUG: Duration.rst is causing ipython issues

DOC: VAR examples not running

revert changes to statespace

typo in regression

print statement

missing import
@TomAugspurger

Copy link
Copy Markdown
Contributor Author

https://gist.github.com/7524a3144d9c87806bbf shows all the non-notebook conversion changes. Really it's smaller than that since that diff has the deletion of numpydoc (in TomAugspurger@973ec9b), which is now pip installable, and and update to the ipython_directive.

The dev docs are updated to the build from my last commit.

I think this is pretty much mergeable now. My todo list is

  • include @savefig decorators on all the example plots
  • figure out why duration.rst breaks the execution on index.rst (and possibly elsewhere)
  • integrate into Travis to auto-biuld
  • cache the notebook execution step
  • integrate statsmodels styling / template into HTML notebooks
  • verify the output, make sure all the examples are executed and work
  • fixup any compatibility things (including make.bat!)
  • Pull in wiki examples?
  • partial builds similar to pandas make.py --single

but those may have to wait a bit.

@josef-pkt

Copy link
Copy Markdown
Member

I'm reading through the gist

that's it

general question:
Do we need %matplotlib inline in the notebooks or can this be set outside of the notebook?
I usually just start jupyter or ipython notebook with this option.

@TomAugspurger

Copy link
Copy Markdown
Contributor Author

On Feb 17, 2016, at 10:38 AM, Josef Perktold [email protected] wrote:

I'm reading through the gist

the executed example in the main rst looks good
cross link to notebooks are missing, e.g. after example: Detailed examples can be found here http://www.statsmodels.org/dev/discretemod.html http://www.statsmodels.org/dev/discretemod.html http://statsmodels.sourceforge.net/devel/discretemod.html http://statsmodels.sourceforge.net/devel/discretemod.html
That’s probably from me converting .ipynb -> HTML, and not going through rst. The easiest fix is probably just linking to the rendered HTML directly, which I can do.
executing example instead of hardcoding requires check that they actually work, and are self contained, e.g. docs/source/example_formulas.rst (I didn't look at those yet)
typo in missing.rst print(ls_fit.params) should be print(ols_fit.params) AFAICS
Will fix.
vector_ar.rst is the largest tutorial style rst file: http://www.statsmodels.org/dev/vector_ar.html http://www.statsmodels.org/dev/vector_ar.html http://statsmodels.sourceforge.net/devel/vector_ar.html http://statsmodels.sourceforge.net/devel/vector_ar.html
plots are missing
one known refactoring victim/exception, at the end otherwise it looks much better than I expected, everything else still seems to be working
is docs/sphinxext/ipython_directive.py an updated version? looks like it
Yeah. This isn’t on PyPI, so I just copied it from IPython’s git repo.
info: mixed_lm_example.ipynb contains refactoring corrections
that's it

general question:
Do we need %matplotlib inline in the notebooks or can this be set outside of the notebook?
I usually just start jupyter or ipython notebook with this option.

I believe we do. Jupyter has deprecated the %pylab / %matplotlib command line arguments, in favor setting it inside the notebook. They’ve been removed, at least as of notebook version 4.1.0.

—
Reply to this email directly or view it on GitHub #2816 (comment).

@TomAugspurger
TomAugspurger force-pushed the nb-simple branch 3 times, most recently from cd2e82f to 5dd3a68 Compare February 18, 2016 13:01
@TomAugspurger

Copy link
Copy Markdown
Contributor Author

Ok, this should be ready. I've fixed all the issues I've seen. The plotting in vector_ar.rst is working correctly now. There's probably others I've missed but those can be fixed in a followup.

I've tried to update the make.bat file as well, but it's almost surely broken. I believe MSVS comes with a nmake, Microsoft's version of make. Might be better off using that.

I briefly tried to setup travis last night. It shouldn't take too long to get going, but I ran out of time. I'll pick it up again next week hopefully.

@josef-pkt

Copy link
Copy Markdown
Member

make.bat is working fine for me, but when I wrote/adjusted it, I didn't manage to build the examples and skipped that step in the make.bat.

I give it a brief look again, and merge it.

Thanks a lot.

@josef-pkt

Copy link
Copy Markdown
Member

merging. I might revert the make.bat changes if I run into problems to fix it, or make an extra commands for html with and without example build

josef-pkt added a commit that referenced this pull request Feb 18, 2016
DOC/BLD: Update notebook documentation system
@josef-pkt
josef-pkt merged commit 302c2ec into statsmodels:master Feb 18, 2016
@TomAugspurger TomAugspurger mentioned this pull request Feb 18, 2016
7 of 9 tasks
@TomAugspurger

Copy link
Copy Markdown
Contributor Author

For the build commands, pandas uses a python file that takes command line arguments like python make.py --single=indexing.rst. We could do something like that too to include / exclude notebook builds / execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: Building notebooks fails with some ipython version

2 participants