<commit_before># -*- coding: utf-8 -*-
"""
    tablib.core
    ~~~~~~~~~~~

    This module implements the central tablib objects.

    :copyright: (c) 2011 by <NAME>.
    :license: MIT, see LICENSE for more details.
"""

from copy import copy
from operator import itemgetter

from tablib import formats


__title__ = 'tablib'
__version__ = '0.9.3'
__build__ = 0x000903
__author__ = '<NAME>'
__license__ = 'MIT'
__copyright__ = 'Copyright 2011 <NAME>'


class Row(object):
    """Internal Row object. Mainly used for filtering."""

    __slots__ = ['tuple', '_row', 'tags']

    def __init__(self, row=list(), tags=list()):
        self._row = list(row)
        self.tags = list(tags)

    def __iter__(self):
        return (col for col in self._row)

    def __len__(self):
        return len(self._row)

    def __repr__(self):
        return repr(self._row)

    def __getslice__(self, i, j):
        return self._row[i,j]

    def __getitem__(self, i):
        return self._row[i]

    def __setitem__(self, i, value):
        self._row[i] = value

    def __delitem__(self, i):
        del self._row[i]

    def __getstate__(self):
        return {slot: [getattr(self, slot) for slot in self.__slots__]}

    def __setstate__(self, state):
        for (k, v) in state.items(): setattr(self, k, v)

    def append(self, value):
        self._row.append(value)

    def insert(self, index, value):
        self._row.insert(index, value)

    def __contains__(self, item):
        return (item in self._row)

    @property
    def tuple(self):
        '''Tuple representation of :class:`Row`.'''
        return tuple(self._row)

    @property
    def list(self):
        '''List representation of :class:`Row`.'''
        return list(self._row)

    def has_tag(self, tag):
        """Returns true if current row contains tag."""

        if tag == None:
            return False
        elif isinstance(tag, basestring):
            return (tag in self.tags)
        else:
            return True if len(set(tag) and set(self.tags)) else False


class Dataset(object):
    """The :class:`Dataset` object is the heart of Tablib. It provides all core
    functionality.

    Usually you create a :class:`Dataset` instance in your main module, and append
    rows and columns as you collect data. ::

        data = tablib.Dataset()
        data.headers = ('name', 'age')

        for (name, age) in some_collector():
            data.append((name, age))

    You can also set rows and headers upon instantiation. This is useful if dealing
    with dozens or hundres of :class:`Dataset` objects. ::

        headers = ('first_name', 'last_name')
        data = [('John', 'Adams'), ('George', 'Washington')]

        data = tablib.Dataset(*data, headers=headers)<commit_msg>that makes more sense<commit_after># -*- coding: utf-8 -*-
"""
    tablib.core
    ~~~~~~~~~~~

    This module implements the central tablib objects.

    :copyright: (c) 2011 by <NAME>.
    :license: MIT, see LICENSE for more details.
"""

from copy import copy
from operator import itemgetter

from tablib import formats


__title__ = 'tablib'
__version__ = '0.9.3'
__build__ = 0x000903
__author__ = '<NAME>'
__license__ = 'MIT'
__copyright__ = 'Copyright 2011 <NAME>'


class Row(object):
    """Internal Row object. Mainly used for filtering."""

    __slots__ = ['tuple', '_row', 'tags']

    def __init__(self, row=list(), tags=list()):
        self._row = list(row)
        self.tags = list(tags)

    def __iter__(self):
        return (col for col in self._row)

    def __len__(self):
        return len(self._row)

    def __repr__(self):
        return repr(self._row)

    def __getslice__(self, i, j):
        return self._row[i,j]

    def __getitem__(self, i):
        return self._row[i]

    def __setitem__(self, i, value):
        self._row[i] = value

    def __delitem__(self, i):
        del self._row[i]

    def __getstate__(self):
        return {slot: [getattr(self, slot) for slot in self.__slots__]}

    def __setstate__(self, state):
        for (k, v) in state.items(): setattr(self, k, v)

    def append(self, value):
        self._row.append(value)

    def insert(self, index, value):
        self._row.insert(index, value)

    def __contains__(self, item):
        return (item in self._row)

    @property
    def tuple(self):
        '''Tuple representation of :class:`Row`.'''
        return tuple(self._row)

    @property
    def list(self):
        '''List representation of :class:`Row`.'''
        return list(self._row)

    def has_tag(self, tag):
        """Returns true if current row contains tag."""

        if tag == None:
            return False
        elif isinstance(tag, basestring):
            return (tag in self.tags)
        else:
            return bool(len(set(tag) & set(self.tags)))
                



class Dataset(object):
    """The :class:`Dataset` object is the heart of Tablib. It provides all core
    functionality.

    Usually you create a :class:`Dataset` instance in your main module, and append
    rows and columns as you collect data. ::

        data = tablib.Dataset()
        data.headers = ('name', 'age')

        for (name, age) in some_collector():
            data.append((name, age))

    You can also set rows and headers upon instantiation. This is useful if dealing
    with dozens or hundres of :class:`Dataset` objects. ::

        headers = ('first_name', 'last_name')
        data = [('John', 'Adams'), ('George', 'Washington')]

        data = tablib.Dataset(*data, headers=headers)
{'fraction_non_alphanumeric': 0.1293398093182227, 'fraction_numerical': 0.006835761827666847, 'mean_word_length': 2.568677792041078, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2524325', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1672, 'n_words': 543}