Install
%install_ext https://gist.githubusercontent.com/miraculixx/eb2299bdede8c52b05e1/raw/c582151f9d09a343b6e314983230590e6fe82796/minitb.py
Use
%minitb on
Usual stack traces in ipython are very long, even when using xmode plain. Consider this example:
%xmode plain
def foo(i=0):
if i > 5:
pd.DataFrame({'foo' : [0,1,2]}).apply(lambda s : s.bar)
return
# simulate deep call graph
foo(i+1)
foo()
This results in this very long stack trace:
Exception reporting mode: Plain
Traceback (most recent call last):
File "/Users/patrick/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3066, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-57-c15c8485011b>", line 7, in <module>
foo()
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 6, in foo
foo(i+1)
File "<ipython-input-57-c15c8485011b>", line 4, in foo
pd.DataFrame({'foo' : [0,1,2]}).apply(lambda s : s.bar)
File "/Users/patrick/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 3972, in apply
return self._apply_standard(f, axis, reduce=reduce)
File "/Users/patrick/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 4064, in _apply_standard
results[i] = func(v)
File "<ipython-input-57-c15c8485011b>", line 4, in <lambda>
pd.DataFrame({'foo' : [0,1,2]}).apply(lambda s : s.bar)
File "/Users/patrick/anaconda/lib/python2.7/site-packages/pandas/core/generic.py", line 2360, in __getattr__
(type(self).__name__, name))
AttributeError: ("'Series' object has no attribute 'bar'", u'occurred at index foo')
%minitb
foo()
Traceback reduced to the max:
File "<ipython-input-57-c15c8485011b>", line 4, in <lambda>
pd.DataFrame({'foo' : [0,1,2]}).apply(lambda s : s.bar)
File "/Users/patrick/anaconda/lib/python2.7/site-packages/pandas/core/generic.py", line 2360, in __getattr__
(type(self).__name__, name))
AttributeError: ("'Series' object has no attribute 'bar'", u'occurred at index foo')
- Using the
%fulltb
magic
%fulltb
(will print the full traceback in all its glory)
- Switching back to the usual traceback formatter
%minitb off
# next tb will be formatted as usual