<commit_before>from collections import OrderedDict

import numpy as np

import param

from ..core import Dimension, NdMapping, Element, HoloMap


class ItemTable(Element):
    """
    A tabular element type to allow convenient visualization of either a
    standard Python dictionary or an OrderedDict. If an OrderedDict is
    used, the headings will be kept in the correct order. Tables store
    heterogeneous data with different labels.

    Dimension objects are also accepted as keys, allowing dimensional
    information (e.g type and units) to be associated per heading.
    """

    key_dimensions = param.List(default=[Dimension('Default')], bounds=(1, None), doc="""
       ItemTables hold an index Dimension for each value they contain, i.e.
       they are equivalent to the keys.""")

    value_dimensions = param.List(default=[], bounds=(0, 0), doc="""
       ItemTables should have only index Dimensions.""")

    @property
    def rows(self):
        return self.ndims


    @property
    def cols(self):
        return 2


    def __init__(self, data, **params):
        # Assume OrderedDict if not a vanilla Python dict
        if type(data) == dict:
            data = OrderedDict(sorted(data.items()))

        str_keys=dict((k.name if isinstance(k, Dimension)
                       else k ,v) for (k,v) in data.items())
        params = dict(params, key_dimensions=data.keys())
        super(ItemTable, self).__init__(str_keys, **params)


    def __getitem__(self, heading):
        """
        Get the value associated with the given heading (key).
        """
        if heading is ():
            return self
        if heading not in self._cached_index_names:
            raise IndexError("%r not in available headings." % heading)<commit_msg>Added value parameter to ItemTable<commit_after>from collections import OrderedDict

import numpy as np

import param

from ..core import Dimension, NdMapping, Element, HoloMap


class ItemTable(Element):
    """
    A tabular element type to allow convenient visualization of either a
    standard Python dictionary or an OrderedDict. If an OrderedDict is
    used, the headings will be kept in the correct order. Tables store
    heterogeneous data with different labels.

    Dimension objects are also accepted as keys, allowing dimensional
    information (e.g type and units) to be associated per heading.
    """

    key_dimensions = param.List(default=[Dimension('Default')], bounds=(1, None), doc="""
       ItemTables hold an index Dimension for each value they contain, i.e.
       they are equivalent to the keys.""")

    value_dimensions = param.List(default=[], bounds=(0, 0), doc="""
       ItemTables should have only index Dimensions.""")

    value = param.String(default="ItemTable")

    @property
    def rows(self):
        return self.ndims


    @property
    def cols(self):
        return 2


    def __init__(self, data, **params):
        # Assume OrderedDict if not a vanilla Python dict
        if type(data) == dict:
            data = OrderedDict(sorted(data.items()))

        str_keys=dict((k.name if isinstance(k, Dimension)
                       else k ,v) for (k,v) in data.items())
        params = dict(params, key_dimensions=data.keys())
        super(ItemTable, self).__init__(str_keys, **params)


    def __getitem__(self, heading):
        """
        Get the value associated with the given heading (key).
        """
        if heading is ():
            return self
        if heading not in self._cached_index_names:
            raise IndexError("%r not in available headings." % heading)
{'fraction_non_alphanumeric': 0.09224376731301939, 'fraction_numerical': 0.00221606648199446, 'mean_word_length': 2.7771966527196654, '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': '7529931', 'n_tokens_mistral': 986, 'n_tokens_neox': 945, 'n_words': 369}