The first time I do something that raises a warning in the IPython shell, I see it. But subsequent times I do not. For example,
In [1]: import numpy as np
In [2]: np.uint8(250) * np.uint8(2)
/Users/me/anaconda/envs/py33/bin/ipython:1: RuntimeWarning: overflow encountered in ubyte_scalars
#!/bin/bash /Users/me/anaconda/envs/py33/bin/python.app
Out[2]: 244
In [3]: np.uint8(250) * np.uint8(2)
Out[3]: 244 # No warning!
How do I configure IPython to always show warnings? I've tried:
import warnings
warnings.filterwarnings('always')
But that doesn't make any difference.
IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. from __future__ import print_function import sys. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
The “%timeit” is a line magic command in which the code consists of a single line or should be written in the same line for measuring the execution time. In the “%timeit” command, the particular code is specified after the “%timeit” is separated by a space.
As a first example, you can use the magic command %lsmagic to list the available magic commands (Figure 3.11). To get the output you have to execute the cell as with any other code cell. The %load_ext magic command can be used for loading IPython extension which can add new magic commands.
I think this was addressed relatively recently by the IPython team. It wasn't playing well with warnings
because of a somewhat unusual design decision. Turing on always
suffices for me in plain Python, and now if I do the same thing in IPython trunk:
In [1]: import warnings
In [2]: warnings.filterwarnings('always')
In [3]: import numpy as np
In [4]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
#!/home/dsm/sys/root/bin/python3.4
Out[4]: 244
In [5]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
#!/home/dsm/sys/root/bin/python3.4
Out[5]: 244
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With