From 1ca3ff5e37a47a6dde98673bdf0bf60488e0a751 Mon Sep 17 00:00:00 2001 From: Roger Labbe Date: Fri, 2 Feb 2018 10:51:00 -0800 Subject: [PATCH] Fixed numpy set_printoptions for reasons I don't understand you have to call with suprres=True and no othe rparameters for it to 'work', even though the get_printoptions shows it as correctly set. --- book_format.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/book_format.py b/book_format.py index 766d844..6c42127 100644 --- a/book_format.py +++ b/book_format.py @@ -34,7 +34,6 @@ from kf_book.book_plots import set_figsize, reset_axis if matplotlib.__version__ == '1.4.3': warnings.simplefilter(action="ignore", category=FutureWarning) -np.set_printoptions(precision=3) try: matplotlib.style.use('default') except: @@ -46,7 +45,7 @@ def test_filterpy_version(): from distutils.version import LooseVersion v = filterpy.__version__ - min_version = "1.2.0" + min_version = "1.2.1" if LooseVersion(v) < LooseVersion(min_version): raise Exception("Minimum FilterPy version supported is {}.\n" "Please install a more recent version.\n" @@ -118,9 +117,13 @@ def load_style(directory = '.', name='kf_book/custom.css'): pass set_figsize() reset_axis () - np.set_printoptions(suppress=True, precision=3, linewidth=70, + np.set_printoptions(suppress=True, precision=3, + threshold=10000., linewidth=70, formatter={'float':lambda x:' {:.3}'.format(x)}) - styles = open(os.path.join(directory, name), 'r').read() set_figsize() + # I don't know why I have to do this, but I have to call + # with suppress a second time or the notebook doesn't suppress + # exponents + np.set_printoptions(suppress=True) return HTML(styles)