Exemple #1
0
def test_set_defaults():
    fake_grid_options_a = {'foo': 'bar'}
    set_defaults(show_toolbar=False, precision=4,
                 grid_options=fake_grid_options_a)

    def assert_widget_vals_a(widget):
        assert not widget.show_toolbar
        assert widget.precision == 4
        assert widget.grid_options == fake_grid_options_a

    df = create_df()
    view = show_grid(df)
    assert_widget_vals_a(view)

    view = QgridWidget(df=df)
    assert_widget_vals_a(view)

    fake_grid_options_b = {'foo': 'buzz'}
    set_defaults(show_toolbar=True, precision=2,
                 grid_options=fake_grid_options_b)

    def assert_widget_vals_b(widget):
        assert widget.show_toolbar
        assert widget.precision == 2
        assert widget.grid_options == fake_grid_options_b

    df = create_df()
    view = show_grid(df)
    assert_widget_vals_b(view)

    view = QgridWidget(df=df)
    assert_widget_vals_b(view)
Exemple #2
0
def test_set_defaults():
    fake_grid_options_a = {'foo': 'bar'}
    set_defaults(show_toolbar=False,
                 precision=4,
                 grid_options=fake_grid_options_a)

    def assert_widget_vals_a(widget):
        assert not widget.show_toolbar
        assert widget.precision == 4
        assert widget.grid_options == fake_grid_options_a

    df = create_df()
    view = show_grid(df)
    assert_widget_vals_a(view)

    view = QgridWidget(df=df)
    assert_widget_vals_a(view)

    fake_grid_options_b = {'foo': 'buzz'}
    set_defaults(show_toolbar=True,
                 precision=2,
                 grid_options=fake_grid_options_b)

    def assert_widget_vals_b(widget):
        assert widget.show_toolbar
        assert widget.precision == 2
        assert widget.grid_options == fake_grid_options_b

    df = create_df()
    view = show_grid(df)
    assert_widget_vals_b(view)

    view = QgridWidget(df=df)
    assert_widget_vals_b(view)
Exemple #3
0
def show_grid(z, force_fit=False):
    import qgrid

    qgrid.set_defaults(remote_js=True, precision=4)

    new = pd.DataFrame()
    for x in z.columns:
        new[" ".join(x)] = z[x]
    return qgrid.show_grid(new, grid_options={"forceFitColumns": force_fit, "defaultColumnWidth": 120})
Exemple #4
0
def use_qgrid(key):
    import qgrid

    if shell == "ZMQInteractiveShell":
        if cf.get_option(key):
            qgrid.enable()
            qgrid.set_defaults(show_toolbar=True)
        else:
            qgrid.disable()
Exemple #5
0
    def jsdf(self, line):
        """
        defines ``%jsdf``
        which displays a pandas dataframe into a notebook using qgrid (javascript)

        .. nbref::
            :title: jsdf

            The magic command ``%jsdf`` displays a dataframe using
            `qgrid <https://qgrid.readthedocs.io/en/latest/>`_ module.
            The code is the following::

                import qgrid
                if firt_call:
                    qgrid.set_defaults(precision=<precision>)
                    self.first_jsdf_call = False

                df = args.df
                grid_options = dict(defaultColumnWidth=<defaultColumnWidth>,
                                    enableColumnReorder=<enableColumnReorder>,
                                    multiColumnSort=<multiColumnSort>,
                                    rowHeight=<rowHeight>,
                                    showHeaderRow=<showHeaderRow>,
                                    forceFitColumns=<forceFitColumns>,
                                    autoHeight=<autoHeight>,
                                    enableCellNavigation=<enableCellNavigation>)
                qgrid.show_grid(df, grid_options=grid_options)
        """
        parser = self.get_parser(MagicNotebook.jsdf_parser, "jsdf")
        args = self.get_args(line, parser)

        if qgrid is None:
            return "qgrid is not installed."

        if not hasattr(self, "first_jsdf_call") or self.first_jsdf_call:
            if args is not None:
                qgrid.set_defaults(precision=args.precision)
            else:
                qgrid.set_defaults()
            self.first_jsdf_call = False

        if args is not None:
            df = args.df
            grid_options = dict(defaultColumnWidth=args.defaultColumnWidth,
                                enableColumnReorder=args.enableColumnReorder,
                                multiColumnSort=args.multiColumnSort,
                                rowHeight=args.rowHeight,
                                showHeaderRow=args.showHeaderRow,
                                forceFitColumns=args.forceFitColumns,
                                autoHeight=args.autoHeight,
                                enableCellNavigation=args.enableCellNavigation,
                                editable=args.editable)
            res = qgrid.show_grid(df, grid_options=grid_options)
            return "" if res is None else res
Exemple #6
0
def show_grid(z, force_fit=False):
    import qgrid
    qgrid.set_defaults(remote_js=True, precision=4)

    new = pd.DataFrame()
    for x in z.columns:
        new[' '.join(x)] = z[x]
    return qgrid.show_grid(new,
                           grid_options={
                               'forceFitColumns': force_fit,
                               'defaultColumnWidth': 120
                           })
Exemple #7
0
    def jsdf(self, line):
        """
        defines ``%jsdf``
        which displays a pandas dataframe into a notebook using qgrid (javascript)

        .. nbref::
            :title: jsdf

            The magic command ``%jsdf`` displays a dataframe using
            `qgrid <https://qgrid.readthedocs.io/en/latest/>`_ module.
            The code is the following::

                import qgrid
                if firt_call:
                    qgrid.set_defaults(precision=<precision>)
                    self.first_jsdf_call = False

                df = args.df
                grid_options = dict(defaultColumnWidth=<defaultColumnWidth>,
                                    enableColumnReorder=<enableColumnReorder>,
                                    multiColumnSort=<multiColumnSort>,
                                    rowHeight=<rowHeight>,
                                    showHeaderRow=<showHeaderRow>,
                                    forceFitColumns=<forceFitColumns>,
                                    autoHeight=<autoHeight>,
                                    enableCellNavigation=<enableCellNavigation>)
                qgrid.show_grid(df, grid_options=grid_options)
        """
        parser = self.get_parser(MagicNotebook.jsdf_parser, "jsdf")
        args = self.get_args(line, parser)

        if not hasattr(self, "first_jsdf_call") or self.first_jsdf_call:
            if args is not None:
                qgrid.set_defaults(precision=args.precision)
            else:
                qgrid.set_defaults()
            self.first_jsdf_call = False

        if args is not None:
            df = args.df
            grid_options = dict(defaultColumnWidth=args.defaultColumnWidth,
                                enableColumnReorder=args.enableColumnReorder,
                                multiColumnSort=args.multiColumnSort,
                                rowHeight=args.rowHeight,
                                showHeaderRow=args.showHeaderRow,
                                forceFitColumns=args.forceFitColumns,
                                autoHeight=args.autoHeight,
                                enableCellNavigation=args.enableCellNavigation,
                                editable=args.editable)
            res = qgrid.show_grid(df, grid_options=grid_options)
            return "" if res is None else res
Exemple #8
0
# ---

# %% [markdown]
# ### working out how to do a basic interactive CSV/dataframe in jupyter
# try using qgrid + buttons first

# %%
import pandas as pd
import ipywidgets
import qgrid

# note may want to try with %asyncio to do automatic updating

# %%
# set up defaults
qgrid.set_defaults(precision=2)

# allow jupyternotebook to use full width
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))


# %%
class CsvGridWidget:
    """
    Idea is to make it easy to view and edit a csv file (or anyting loadable by pandas)
    into jupyter notebook. 
    """
    def __init__(self, file_name, **kwargs_read_csv):
        self.file_name = file_name
        default_options = {"keep_default_na": False}
Exemple #9
0
import seaborn as sns
from traitlets import HasTraits, Int
from ipywidgets import DOMWidget
from traitlets import Unicode, Int,List
import StringIO
import numpy as np
import pandas as pd
import json
import IPython.display as display
import matplotlib.ticker as mtick
import matplotlib.pyplot as plt

sm=shotManager.ShotManager(wrapper.signalWrapper)
qgrid.nbinstall(overwrite=True)
qgrid.set_defaults(remote_js=True, precision=4)

def listShots(criterion=None,attrList=None,gui=False):
    """Display the list of discharges with the associated parameters

    criterion: String to select discharges based on the value of the parameters
    attrList: list of parameters to display
    
    Returns: pandas DataFrame
    """    
    
    result=sm.listShots(criterion,attrList)    
    if gui==True:
        qgrid.show_grid(result)     
    return result
        
Exemple #10
0
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
from warnings import filterwarnings
filterwarnings("ignore")
import os
os.environ['MKL_THREADING_LAYER']='GNU'
os.environ['THEANO_FLAGS']='cuda.root=/usr/local/cuda,device=cuda*,floatX=float32,lib.cnmem=0'
import numpy as np
import pandas as pd
import qgrid                   # for beautiful tables
qgrid.set_defaults(show_toolbar = True)
import theano
import theano.tensor as tt
import pymc3 as pm
import dask.dataframe as dd
import pickle
import seaborn as sns             # for static plots
import matplotlib.pyplot as plt
from bqplot import *              # for interactive plots
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as ipw
fig_layout = ipw.Layout(width = "100%", height = "600px")
sns.set_context('notebook', font_scale = 1.1)
np.random.seed(12345)
rc = {'xtick.labelsize': 20, 'ytick.labelsize': 20, 'axes.labelsize': 15, 'font.size': 20,
      'lines.linewidth': 4.0, 'lines.markersize': 40, 'font.family': "serif", 'font.serif': "cm",
      'savefig.dpi': 200, 'text.usetex': False, 'legend.fontsize': 20.0, 'axes.titlesize': 20, 
      "figure.figsize": [20, 12]}
sns.set(rc = rc)
sns.set_style("whitegrid") # or ticks
from IPython.core.interactiveshell import InteractiveShell