<commit_before>from collections import OrderedDict

import numpy as np
import matplotlib.pyplot as plt
import pandas
import seaborn

# from bokeh import plotting
# from bokeh.models import HoverTool

from . import misc


def checkAx(ax):
    '''
    Pass in an Axes or None, get back an Axes and a Figure
    '''
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = ax.figure

    return fig, ax


def plotReachDF(boundary, xcol, ycol, flip=False):
    if not isinstance(boundary, pandas.DataFrame):
        raise ValueError('`boundary` must be a dataframe')

    fg = seaborn.FacetGrid(data=boundary, legend_out=False, size=5,
                           hue='beta', hue_kws={'marker': ['s', 'o', '^']})
    fg.axes[0, 0].plot(boundary[xcol], boundary[ycol], 'k-')
    fg.map(plt.plot, xcol, ycol, linestyle='none')
    fg.add_legend()
    return fg


def plotPygridgen(grid, ax=None):
    fig, ax = checkAx(ax)
    ax.plot(grid.xbry, grid.ybry, 'k-', label='boundary',
            zorder=10, alpha=0.5, linewidth=1.5)

    if ax.is_first_col():
        ax.set_ylabel('$ny = {}$'.format(grid.ny), size=14)

    if ax.is_last_row():
        ax.set_xlabel('$nx = {}$'.format(grid.nx), size=14)

    fig, ax = plotCells(grid.x, grid.y, ax=ax, engine='mpl')
    return fig, ax


def plotCells(nodes_x, nodes_y, name='test', engine='bokeh',
              mask=None, ax=None):
    nodes_x = np.ma.asarray(nodes_x)
    nodes_y = np.ma.asarray(nodes_y)
    if not np.all(nodes_x.shape == nodes_y.shape):
        raise ValueError("nodes_x and nodes_y must be the same shape")

    if not np.all(nodes_x.mask == nodes_y.mask):
        raise ValueError("node arrays must have identical masks")

    #pragma: no cover
    if engine.lower() == 'bokeh':
        raise NotImplementedError("'bokeh' is not an implemented engine (yet)".format(engine))
        p = _plot_cells_bokeh(nodes_x, nodes_y, name=name)
        return p

    elif engine.lower() in ('mpl', 'matplotlib', 'sns', 'seaborn'):
        fig = _plot_cells_mpl(nodes_x, nodes_y, ax=ax, mask=mask)
        return fig

    else:
        raise NotImplementedError("'{}' is not a valid engine".format(engine))


#pragma: no cover
def _plot_cells_bokeh(nodes_x, nodes_y, name='test'):
    raise NotImplementedError

    def getCellColor(row, col):
        return 'blue'

    cell_x = []
    cell_y = []
    cell_color = []

    for row in range(nodes_x.shape[0] - 1):
        for col in range(nodes_x.shape[1] - 1):
            top_x = nodes_x[row:row+2, col]
            bot_x = nodes_x[row:row+2, col+1][::-1]
            cell_x.append(np.hstack([top_x, bot_x]).tolist())<commit_msg>try the pragma again<commit_after>from collections import OrderedDict

import numpy as np
import matplotlib.pyplot as plt
import pandas
import seaborn

# from bokeh import plotting
# from bokeh.models import HoverTool

from . import misc


def checkAx(ax):
    '''
    Pass in an Axes or None, get back an Axes and a Figure
    '''
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = ax.figure

    return fig, ax


def plotReachDF(boundary, xcol, ycol, flip=False):
    if not isinstance(boundary, pandas.DataFrame):
        raise ValueError('`boundary` must be a dataframe')

    fg = seaborn.FacetGrid(data=boundary, legend_out=False, size=5,
                           hue='beta', hue_kws={'marker': ['s', 'o', '^']})
    fg.axes[0, 0].plot(boundary[xcol], boundary[ycol], 'k-')
    fg.map(plt.plot, xcol, ycol, linestyle='none')
    fg.add_legend()
    return fg


def plotPygridgen(grid, ax=None):
    fig, ax = checkAx(ax)
    ax.plot(grid.xbry, grid.ybry, 'k-', label='boundary',
            zorder=10, alpha=0.5, linewidth=1.5)

    if ax.is_first_col():
        ax.set_ylabel('$ny = {}$'.format(grid.ny), size=14)

    if ax.is_last_row():
        ax.set_xlabel('$nx = {}$'.format(grid.nx), size=14)

    fig, ax = plotCells(grid.x, grid.y, ax=ax, engine='mpl')
    return fig, ax


def plotCells(nodes_x, nodes_y, name='test', engine='bokeh',
              mask=None, ax=None):
    nodes_x = np.ma.asarray(nodes_x)
    nodes_y = np.ma.asarray(nodes_y)
    if not np.all(nodes_x.shape == nodes_y.shape):
        raise ValueError("nodes_x and nodes_y must be the same shape")

    if not np.all(nodes_x.mask == nodes_y.mask):
        raise ValueError("node arrays must have identical masks")

    # pragma: no cover
    if engine.lower() == 'bokeh':
        raise NotImplementedError("'bokeh' is not an implemented engine (yet)".format(engine))
        p = _plot_cells_bokeh(nodes_x, nodes_y, name=name)
        return p

    elif engine.lower() in ('mpl', 'matplotlib', 'sns', 'seaborn'):
        fig = _plot_cells_mpl(nodes_x, nodes_y, ax=ax, mask=mask)
        return fig

    else:
        raise NotImplementedError("'{}' is not a valid engine".format(engine))


# pragma: no cover
def _plot_cells_bokeh(nodes_x, nodes_y, name='test'):
    raise NotImplementedError

    def getCellColor(row, col):
        return 'blue'

    cell_x = []
    cell_y = []
    cell_color = []

    for row in range(nodes_x.shape[0] - 1):
        for col in range(nodes_x.shape[1] - 1):
            top_x = nodes_x[row:row+2, col]
            bot_x = nodes_x[row:row+2, col+1][::-1]
            cell_x.append(np.hstack([top_x, bot_x]).tolist())
{'fraction_non_alphanumeric': 0.14078674948240166, 'fraction_numerical': 0.007905138339920948, 'mean_word_length': 2.9188790560471976, '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': '2051885', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1886, 'n_words': 468}