##// END OF EJS Templates
Reset the interactive namespace __warningregistry__ before executing code...
Reset the interactive namespace __warningregistry__ before executing code Fixes #6611. Idea: Right now, people often don't see important warnings when running code in IPython, because (to a first approximation) any given warning will only issue once per session. Blink and you'll miss it! This is a very common contributor to confused emails to numpy-discussion. E.g.: In [5]: 1 / my_array_with_random_contents /home/njs/.user-python2.7-64bit-3/bin/ipython:1: RuntimeWarning: divide by zero encountered in divide #!/home/njs/.user-python2.7-64bit-3/bin/python Out[5]: array([ 1.77073316, -2.29765021, -2.01800811, ..., 1.13871243, -1.08302964, -8.6185091 ]) Oo, right, guess I gotta be careful of those zeros -- thanks, numpy, for giving me that warning! A few days later: In [592]: 1 / some_other_array Out[592]: array([ 3.07735763, 0.50769289, 0.83984078, ..., -0.67563917, -0.85736257, -1.36511271]) Oops, it turns out that this array had a zero in it too, and that's going to bite me later. But no warning this time! The effect of this commit is to make it so that warnings triggered by the code in cell 5 do *not* suppress warnings triggered by the code in cell 592. Note that this only applies to warnings triggered *directly* by code entered interactively -- if somepkg.foo() calls anotherpkg.bad_func() which issues a warning, then this warning will still only be displayed once, even if multiple cells call somepkg.foo(). But if cell 5 and cell 592 both call anotherpkg.bad_func() directly, then both will get warnings. (Important exception: if foo() is defined *interactively*, and calls anotherpkg.bad_func(), then every cell that calls foo() will display the warning again. This is unavoidable without fixes to CPython upstream.) Explanation: Python's warning system has some weird quirks. By default, it tries to suppress duplicate warnings, where "duplicate" means the same warning message triggered twice by the same line of code. This requires determining which line of code is responsible for triggering a warning, and this is controlled by the stacklevel= argument to warnings.warn. Basically, though, the idea is that if foo() calls bar() which calls baz() which calls some_deprecated_api(), then baz() will get counted as being "responsible", and the warning system will make a note that the usage of some_deprecated_api() inside baz() has already been warned about and doesn't need to be warned about again. So far so good. To accomplish this, obviously, there has to be a record of somewhere which line this was. You might think that this would be done by recording the filename:linenumber pair in a dict inside the warnings module, or something like that. You would be wrong. What actually happens is that the warnings module will use stack introspection to reach into baz()'s execution environment, create a global (module-level) variable there named __warningregistry__, and then, inside this dictionary, record just the line number. Basically, it assumes that any given module contains only one line 1, only one line 2, etc., so storing the filename is irrelevant. Obviously for interactive code this is totally wrong -- all cells share the same execution environment and global namespace, and they all contain a new line 1. Currently the warnings module treats these as if they were all the same line. In fact they are not the same line; once we have executed a given chunk of code, we will never see those particular lines again. As soon as a given chunk of code finishes executing, its line number labels become meaningless, and the corresponding warning registry entries become meaningless as well. Therefore, with this patch we delete the __warningregistry__ each time we execute a new block of code.

File last commit:

r17836:efd88a8d
r18548:61431d7d
Show More
development.rst
158 lines | 6.1 KiB | text/x-rst | RstLexer

Development version

This document describes in-flight development work.

Warning

Please do not edit this file by hand (doing so will likely cause merge conflicts for other Pull Requests). Instead, create a new file in the docs/source/whatsnew/pr folder

Using different kernels

Screenshot of notebook kernel selection dropdown menu

You can now choose a kernel for a notebook within the user interface, rather than starting up a separate notebook server for each kernel you want to use. The syntax highlighting adapts to match the language you're working in.

Information about the kernel is stored in the notebook file, so when you open a notebook, it will automatically start the correct kernel.

It is also easier to use the Qt console and the terminal console with other kernels, using the --kernel flag:

ipython qtconsole --kernel bash
ipython console --kernel bash

# To list available kernels
ipython kernelspec list

Kernel authors should see :ref:`kernelspecs` for how to register their kernels with IPython so that these mechanisms work.

Typing unicode identifiers

/_images/unicode_completion.png

Complex expressions can be much cleaner when written with a wider choice of characters. Python 3 allows unicode identifiers, and IPython 3 makes it easier to type those, using a feature from Julia. Type a backslash followed by a LaTeX style short name, such as \alpha. Press tab, and it will turn into α.

Other new features

  • :class:`~.TextWidget` and :class:`~.TextareaWidget` objects now include a placeholder attribute, for displaying placeholder text before the user has typed anything.

  • The %load magic can now find the source for objects in the user namespace. To enable searching the namespace, use the -n option.

    In [1]: %load -n my_module.some_function
    
  • :class:`~.DirectView` objects have a new :meth:`~.DirectView.use_cloudpickle` method, which works like view.use_dill(), but causes the cloudpickle module from PiCloud's cloud library to be used rather than dill or the builtin pickle module.

  • Added a .ipynb exporter to nbconvert. It can be used by passing --to notebook as a commandline argument to nbconvert.

  • New nbconvert preprocessor called :class:`~.ClearOutputPreprocessor`. This clears the output from IPython notebooks.

  • New preprocessor for nbconvert that executes all the code cells in a notebook. To run a notebook and save its output in a new notebook:

    ipython nbconvert InputNotebook --ExecutePreprocessor.enabled=True --to notebook --output Executed
    
  • Consecutive stream (stdout/stderr) output is merged into a single output in the notebook document. Previously, all output messages were preserved as separate output fields in the JSON. Now, the same merge is applied to the stored output as the displayed output, improving document load time for notebooks with many small outputs.

Backwards incompatible changes

  • :func:`IPython.core.oinspect.getsource` call specification has changed:

    • oname keyword argument has been added for property source formatting
    • is_binary keyword argument has been dropped, passing True had previously short-circuited the function to return None unconditionally
  • Removed the octavemagic extension: it is now available as oct2py.ipython.

  • Creating PDFs with LaTeX no longer uses a post processor. Use nbconvert --to pdf instead of nbconvert --to latex --post pdf.

  • Used https://github.com/jdfreder/bootstrap2to3 to migrate the Notebook to Bootstrap 3.

    Additional changes:

    • Set .tab-content .row 0px; left and right margin (bootstrap default is -15px;)
    • Removed height: @btn_mini_height; from .list_header>div, .list_item>div in tree.less
    • Set #header div margin-bottom: 0px;
    • Set #menus to float: left;
    • Set #maintoolbar .navbar-text to float: none;
    • Added no-padding convienence class.
    • Set border of #maintoolbar to 0px
  • Accessing the container DOM object when displaying javascript has been deprecated in IPython 2.0 in favor of accessing element. Starting with IPython 3.0 trying to access container will raise an error in browser javascript console.

  • IPython.utils.py3compat.open was removed: :func:`io.open` provides all the same functionality.

  • The NotebookManager and /api/notebooks service has been replaced by a more generic ContentsManager and /api/contents service, which supports all kinds of files.

  • The Dashboard now lists all files, not just notebooks and directories.

  • The --script hook for saving notebooks to Python scripts is removed, use :samp:`ipython nbconvert --to python {notebook}` instead.

  • The rmagic extension is deprecated, as it is now part of rpy2. See :mod:`rpy2.ipython.rmagic`.

  • :meth:`~.KernelManager.start_kernel` and :meth:`~.KernelManager.format_kernel_cmd` no longer accept a executable parameter. Use the kernelspec machinery instead.

  • The widget classes have been renamed from *Widget to *. The old names are still functional, but are deprecated. i.e. IntSliderWidget has been renamed to IntSlider.

  • The ContainerWidget was renamed to Box and no longer defaults as a flexible box in the web browser. A new FlexBox widget was added, which allows you to use the flexible box model.

IFrame embedding

The IPython Notebook and its APIs by default will only be allowed to be embedded in an iframe on the same origin.

To override this, set headers[X-Frame-Options] to one of

  • DENY
  • SAMEORIGIN
  • ALLOW-FROM uri

See Mozilla's guide to X-Frame-Options for more examples.