<commit_before>import iris
from iris.util import guess_coord_axis
import numpy as np

import param
from holoviews.core.dimension import Dimension
from holoviews.core.data import DataColumns
from holoviews.core.ndmapping import (NdMapping, item_check,
                                      sorted_context)
from holoviews.core.spaces import HoloMap
from holoviews.core import util
from holoviews.element.tabular import Table


def get_date_format(coord):
    def date_formatter(val, pos=None):
        return coord.units.num2date(val)
    return date_formatter

def coord_to_dimension(coord):
    """
    Converts an iris coordinate to a HoloViews dimension.
    """
    kwargs = {}
    if coord.units.is_time_reference():
        kwargs['value_format'] = get_date_format(coord)
    else:
        kwargs['unit'] = str(coord.units)
    return Dimension(coord.name(), **kwargs)

def sort_coords(coord):
    """
    Sorts a list of DimCoords trying to ensure that
    dates and pressure levels appear first and the
    longitude and latitude appear last in the correct
    order.
    """
    order = {'T': -2, 'Z': -1, 'X': 1, 'Y': 2}
    axis = guess_coord_axis(coord)
    return (order.get(axis, 0), coord and coord.name())


class Cube(Table):
    """
    The Cube Element provides an interface to wrap and display
    :class:`Iris.cube.Cube` objects. The Cube automatically
    infers the key and value dimensions of the iris data
    and provides useful methods for accessing, grouping
    and slicing the data.
    """

    datatype = param.List(default=['cube'])

    group = param.String(default='Cube')



class CubeData(DataColumns):

    types = (iris.cube.Cube,)

    datatype = 'cube'

    @classmethod
    def reshape(cls, eltype, data, kdims, vdims):
        if not isinstance(data, iris.cube.Cube):
            raise TypeError('Cube data must be be an iris Cube type.')

        if kdims:
            if len(kdims) != len(data.dim_coords):
                raise ValueError('Supplied key dimensions must match Cube dim_coords.')
            coords = []
            for kd in kdims:
                coord = data.coords(kd.name if isinstance(kd, Dimension) else kd)
                if len(coord) == 0:
                    raise ValueError('Key dimension %s not found in Iris cube.' % kd)
                coords.append(coord[0])
        else:<commit_msg>Renamed CubeData interface reshape method to match HoloViews<commit_after>import iris
from iris.util import guess_coord_axis
import numpy as np

import param
from holoviews.core.dimension import Dimension
from holoviews.core.data import DataColumns
from holoviews.core.ndmapping import (NdMapping, item_check,
                                      sorted_context)
from holoviews.core.spaces import HoloMap
from holoviews.core import util
from holoviews.element.tabular import Table


def get_date_format(coord):
    def date_formatter(val, pos=None):
        return coord.units.num2date(val)
    return date_formatter

def coord_to_dimension(coord):
    """
    Converts an iris coordinate to a HoloViews dimension.
    """
    kwargs = {}
    if coord.units.is_time_reference():
        kwargs['value_format'] = get_date_format(coord)
    else:
        kwargs['unit'] = str(coord.units)
    return Dimension(coord.name(), **kwargs)

def sort_coords(coord):
    """
    Sorts a list of DimCoords trying to ensure that
    dates and pressure levels appear first and the
    longitude and latitude appear last in the correct
    order.
    """
    order = {'T': -2, 'Z': -1, 'X': 1, 'Y': 2}
    axis = guess_coord_axis(coord)
    return (order.get(axis, 0), coord and coord.name())


class Cube(Table):
    """
    The Cube Element provides an interface to wrap and display
    :class:`Iris.cube.Cube` objects. The Cube automatically
    infers the key and value dimensions of the iris data
    and provides useful methods for accessing, grouping
    and slicing the data.
    """

    datatype = param.List(default=['cube'])

    group = param.String(default='Cube')



class CubeData(DataColumns):

    types = (iris.cube.Cube,)

    datatype = 'cube'

    @classmethod
    def init(cls, eltype, data, kdims, vdims):
        if not isinstance(data, iris.cube.Cube):
            raise TypeError('Cube data must be be an iris Cube type.')

        if kdims:
            if len(kdims) != len(data.dim_coords):
                raise ValueError('Supplied key dimensions must match Cube dim_coords.')
            coords = []
            for kd in kdims:
                coord = data.coords(kd.name if isinstance(kd, Dimension) else kd)
                if len(coord) == 0:
                    raise ValueError('Key dimension %s not found in Iris cube.' % kd)
                coords.append(coord[0])
        else:
{'fraction_non_alphanumeric': 0.09441879983214435, 'fraction_numerical': 0.003357112882920688, 'mean_word_length': 2.6896284829721364, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7214636', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1434, 'n_words': 450}