<commit_before>import collections
import copy
import numpy as np

from LABelsToolkit.tools.aux_methods.sanity_checks import is_valid_permutation
from LABelsToolkit.tools.descriptions.label_descriptor_manager import descriptor_standard_header


def permute_labels_from_descriptor(in_ldm, permutation):
    """
    Given a permutation, as specified in
    Save on the same place: yes it is destructive, but results can be undone with the inverse permutation
    :param in_ldm: instance of a class labels descriptor manager.
    :param permutation: a permutation defined by a list of integers (checked by is_valid_permutation under
    sanity_check).
    :return:
    """
    if not is_valid_permutation(permutation):
        raise IOError('Not valid permutation, please see the docs.')
    # out_ldm = copy.copy(in_ldm)
    for k1, k2 in zip(permutation[0], permutation[1]):
        print(k1, k2)
        print
        in_ldm.dict_label_descriptor[k1], in_ldm.dict_label_descriptor[k2] = \
            in_ldm.dict_label_descriptor[k2], in_ldm.dict_label_descriptor[k1]
    return in_ldm

<commit_msg>BUG to be corrected permutation of labels in labels descriptor<commit_after>import collections
import copy
import numpy as np

from LABelsToolkit.tools.aux_methods.sanity_checks import is_valid_permutation
from LABelsToolkit.tools.descriptions.label_descriptor_manager import descriptor_standard_header


def permute_labels_from_descriptor(in_ldm, permutation):
    """
    Given a permutation, as specified in
    Save on the same place: yes it is destructive, but results can be undone with the inverse permutation
    :param in_ldm: instance of a class labels descriptor manager.
    :param permutation: a permutation defined by a list of integers (checked by is_valid_permutation under
    sanity_check).
    :return:
    """
    # Not working test in progress
    if not is_valid_permutation(permutation):
        raise IOError('Not valid permutation, please see the docs.')
    # out_ldm = copy.copy(in_ldm)
    for k1, k2 in zip(permutation[0], permutation[1]):
        print(k1, k2)
        print
        in_ldm.dict_label_descriptor[k1], in_ldm.dict_label_descriptor[k2] = \
            in_ldm.dict_label_descriptor[k2], in_ldm.dict_label_descriptor[k1]
    return in_ldm


{'fraction_non_alphanumeric': 0.06535087719298245, 'fraction_numerical': 0.008771929824561403, 'mean_word_length': 4.114349775784754, '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': '5759251', 'n_tokens_mistral': 728, 'n_tokens_neox': 680, 'n_words': 206}