<commit_before>""" Named groups via indices

This module implements the base-class which allows named indices

>>> nidx = NamedIndex('hello', [1, 2])
"""
import numpy as np
from numpy import ndarray, bool_

from ._indices import indices_only
from ._array import arrayi
from ._help import _str
from .messages import SislError
from .utils.ranges import list2str


class NamedIndex(object):
    __slots__ = ('_name', '_index')

    def __init__(self, name=None, index=None):
        if isinstance(name, dict):
            # Also allow dictionary inputs!
            self.__init__(name.keys(), name.values())
            return

        # Initialize lists
        self._name = []
        self._index = []

        if isinstance(name, _str):
            self.add_name(name, index)
        elif not name is None:
            for n, i in zip(name, index):
                self.add_name(n, i)

    @property
    def names(self):
        """ All names contained """
        return self._name

    def clear(self):
        """ Clear all names in this object, no names will exist after this call (in-place) """
        self._name.clear()
        self._index.clear()

    def __iter__(self):
        """ Iterate names in the group """
        for name in self._name:
            yield name

    def __len__(self):
        """ Number of uniquely defined names """
        return len(self._name)

    def copy(self):
        """ Create a copy of this """
        return self.__class__(self._name[:], [i.copy() for i in self._index])
<commit_msg>bug: fixed py2.7 clear<commit_after>""" Named groups via indices

This module implements the base-class which allows named indices

>>> nidx = NamedIndex('hello', [1, 2])
"""
import numpy as np
from numpy import ndarray, bool_

from ._indices import indices_only
from ._array import arrayi
from ._help import _str
from .messages import SislError
from .utils.ranges import list2str


class NamedIndex(object):
    __slots__ = ('_name', '_index')

    def __init__(self, name=None, index=None):
        if isinstance(name, dict):
            # Also allow dictionary inputs!
            self.__init__(name.keys(), name.values())
            return

        # Initialize lists
        self._name = []
        self._index = []

        if isinstance(name, _str):
            self.add_name(name, index)
        elif not name is None:
            for n, i in zip(name, index):
                self.add_name(n, i)

    @property
    def names(self):
        """ All names contained """
        return self._name

    def clear(self):
        """ Clear all names in this object, no names will exist after this call (in-place) """
        self._name = []
        self._index = []

    def __iter__(self):
        """ Iterate names in the group """
        for name in self._name:
            yield name

    def __len__(self):
        """ Number of uniquely defined names """
        return len(self._name)

    def copy(self):
        """ Create a copy of this """
        return self.__class__(self._name[:], [i.copy() for i in self._index])

{'fraction_non_alphanumeric': 0.11027732463295269, 'fraction_numerical': 0.0026101141924959217, 'mean_word_length': 2.2721451440768408, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7277871', 'n_tokens_mistral': 870, 'n_tokens_neox': 845, 'n_words': 303}