<commit_before>from tempfile import NamedTemporaryFile

import plotly.offline as py
import plotly.graph_objs as go

from IPython import get_ipython
from ipykernel import zmqshell

DEFAULT_NAME = 'plotly_figure'

def detect_notebook():
    """
    this isn't 100% correct but seems good enough
    """
    kernel = get_ipython()
    return isinstance(kernel, zmqshell.ZMQInteractiveShell)


def _merge_dicts(d1, d2):
    d = d2.copy()
    d.update(d1)
    return d


class Plot(object):
    def __init__(self, data=None, layout=None, **kargs):
        self.data = data
        if data is None:
            self.data = []
        self.layout = layout
        if layout is None:
            self.layout = {}

    def __add__(self, other):
        self.data += other.data
        self.layout = _merge_dicts(self.layout, other.layout)
        return self

    def __radd__(self, other):
        return self.__add__(other)

    def group(self):
        self.layout['barmode'] = 'group'
        return self

    def stack(self):
        self.layout['barmode'] = 'stack'
        return self

    def xlabel(self, label):
        self.layout['xaxis'] = {'title': label}
        return self

    def ylabel(self, label):
        self.layout['yaxis'] = {'title': label}
        return self

    def show(self, filename=None):
        is_notebook = detect_notebook()
        kargs = {}
        if is_notebook:
            py.init_notebook_mode()
            plot = py.iplot
        else:
            plot = py.plot
            if filename is None:
                filename = NamedTemporaryFile(prefix='plotly', suffix='.html', delete=False).name
            kargs['filename'] = filename

        fig = go.Figure(data=self.data, layout=go.Layout(**self.layout))
        plot(fig, **kargs)


class Scatter(Plot):
    def __init__(self, x, y, label=None, **kargs):
        data = [go.Scatter(x=x, y=y, name=label)]
        super(Scatter, self).__init__(data=data)


class Bar(Plot):
    def __init__(self, x, y, label=None, mode='group', **kargs):
        data = [go.Bar(x=x, y=y, name=label)]
        layout = {'barmode': 'group'}
        super(Bar, self).__init__(data=data, layout=layout)


<commit_msg>remove unused const<commit_after>from tempfile import NamedTemporaryFile

import plotly.offline as py
import plotly.graph_objs as go

from IPython import get_ipython
from ipykernel import zmqshell


def detect_notebook():
    """
    this isn't 100% correct but seems good enough
    """
    kernel = get_ipython()
    return isinstance(kernel, zmqshell.ZMQInteractiveShell)


def _merge_dicts(d1, d2):
    d = d2.copy()
    d.update(d1)
    return d


class Plot(object):
    def __init__(self, data=None, layout=None, **kargs):
        self.data = data
        if data is None:
            self.data = []
        self.layout = layout
        if layout is None:
            self.layout = {}

    def __add__(self, other):
        self.data += other.data
        self.layout = _merge_dicts(self.layout, other.layout)
        return self

    def __radd__(self, other):
        return self.__add__(other)

    def group(self):
        self.layout['barmode'] = 'group'
        return self

    def stack(self):
        self.layout['barmode'] = 'stack'
        return self

    def xlabel(self, label):
        self.layout['xaxis'] = {'title': label}
        return self

    def ylabel(self, label):
        self.layout['yaxis'] = {'title': label}
        return self

    def show(self, filename=None):
        is_notebook = detect_notebook()
        kargs = {}
        if is_notebook:
            py.init_notebook_mode()
            plot = py.iplot
        else:
            plot = py.plot
            if filename is None:
                filename = NamedTemporaryFile(prefix='plotly', suffix='.html', delete=False).name
            kargs['filename'] = filename

        fig = go.Figure(data=self.data, layout=go.Layout(**self.layout))
        plot(fig, **kargs)


class Scatter(Plot):
    def __init__(self, x, y, label=None, **kargs):
        data = [go.Scatter(x=x, y=y, name=label)]
        super(Scatter, self).__init__(data=data)


class Bar(Plot):
    def __init__(self, x, y, label=None, mode='group', **kargs):
        data = [go.Bar(x=x, y=y, name=label)]
        layout = {'barmode': 'group'}
        super(Bar, self).__init__(data=data, layout=layout)



{'fraction_non_alphanumeric': 0.12462703695203121, 'fraction_numerical': 0.003213220105577232, 'mean_word_length': 2.3993759750390016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '61100', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1377, 'n_words': 342}