ipython/ipython — pull request #4570 by chebee7i (2013-11-21 01:22:29+00:00)
Title: Update IPython directive

Here are a number of updates to the IPython directive:

- matplotlib is now optional (but on by default). This is configurable through an extension parameter `ipython_mplbackend`. The backend is also configurable, default is `'agg'`.

- The intent of the directive was to automatically add NumPy and pylab to the namespace. This broke recently, but has been fixed. It is also configurable now via the extension parameter `ipython_execlines`. Would it be okay to update the default to include pyplot?

['import numpy as np', 'import matplotlib.pyplot as plt', 'from pylab import *']

- For @doctests within the IPython directive, it can be helpful to fuzzy compare for equality of output. Even if the calculation is performed with a known seed (in the case of stochastic dependence), if the test was written on a slightly different version of software, there could be very small differences which would cause the test to fail. The user can now do:

@doctest float
In [1]: 0.1 + 0.2
Out[1]: 0.3

And this will count as a valid test. The rendered output will display: `0.30000000000000004`. A 2nd and 3rd argument specify the `rtol` and `atol` passed to `np.allclose` (both are required if specified at all). This handles infs, nans, higher dimensional arrays, etc. in very basic scenarios---those you'd expect to run across with documentation examples.

Some additional documentation is still needed, and there's another bug I've found that still needs fixing.