<commit_before>"""This module runs the bokeh server."""

from os.path import dirname, join
from math import ceil, sqrt
from collections import namedtuple

import click
from skimage import io
import numpy as np
import pandas as pd

from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.plotting import figure
from bokeh.layouts import widgetbox, layout
from bokeh.models import (ColumnDataSource,
                          CustomJS,
                          CDSView,
                          GroupFilter,
                          Legend)
from bokeh.models.widgets import Button, DataTable, TableColumn
import bokeh.palettes


def dataframe_from_file(filename):
    """Read in pandas dataframe from filename."""
    df = pd.read_csv(filename, index_col=0).reset_index().set_index('index')
    df['path'] = df['url'].apply(lambda x: join(dirname(filename), x))
    valid_x = df.x.notna()
    valid_y = df.y.notna()
    df = df[valid_x & valid_y]
    return df


def imread(path):
    """Read an image from disk while ensuring it has an alpha channel.

    Parameters
    ----------
    path : string
        Any valid path for skimage.io. This includes a local path as well as
        a URL.

    Returns
    -------
    image : array, shape (M, N, 4)
        The resulting RGBA image.
    """<commit_msg>Remove indexing gymnastics from reading in inconsistent csvs<commit_after>"""This module runs the bokeh server."""

from os.path import dirname, join
from math import ceil, sqrt
from collections import namedtuple

import click
from skimage import io
import numpy as np
import pandas as pd

from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.plotting import figure
from bokeh.layouts import widgetbox, layout
from bokeh.models import (ColumnDataSource,
                          CustomJS,
                          CDSView,
                          GroupFilter,
                          Legend)
from bokeh.models.widgets import Button, DataTable, TableColumn
import bokeh.palettes


def dataframe_from_file(filename):
    """Read in pandas dataframe from filename."""
    df = pd.read_csv(filename, index_col=0)
    df['path'] = df['url'].apply(lambda x: join(dirname(filename), x))
    valid_x = df.x.notna()
    valid_y = df.y.notna()
    df = df[valid_x & valid_y]
    return df


def imread(path):
    """Read an image from disk while ensuring it has an alpha channel.

    Parameters
    ----------
    path : string
        Any valid path for skimage.io. This includes a local path as well as
        a URL.

    Returns
    -------
    image : array, shape (M, N, 4)
        The resulting RGBA image.
    """
{'fraction_non_alphanumeric': 0.0876944837340877, 'fraction_numerical': 0.0014144271570014145, 'mean_word_length': 2.5901015228426396, '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': '5356758', 'n_tokens_mistral': 809, 'n_tokens_neox': 783, 'n_words': 285}