<commit_before>import pandas as pd
import numpy as np
from operator import and_
from six import iteritems
from functools import reduce


def transformGroupToReal(dataframe):
    """ Takes a dataframe and transforms the groups in it to a real representation.

    Args:
        dataframe:

    Returns:
        A copy of the old dataframe, containing the transformed elements.

    """
    mult = len(dataframe)
    l = int((mult-1)/2)
    newDataframe = dataframe.copy()
    for m in range(-l,l+1):        
        valPositive = dataframe.loc[dataframe.t == m, 'value'].values[0]
        valNegative = dataframe.loc[dataframe.t == -m, 'value'].values[0]
        if m < 0:                        
            newValue = (valPositive - ((-1)**m) *valNegative) * 1j/np.sqrt(2)            
        elif m > 0:
            newValue = (valNegative + ((-1)**m) * valPositive) * 1./np.sqrt(2)
        else:
            newValue = valPositive          
        newDataframe.loc[newDataframe.t == m, "value"] = newValue    
    return newDataframe

def filterTmoms(df, **kwargs):
    """ Returns all tensor moments to which the filter arguments in kwargs apply.
        Keys are: atom, species, nu, l1, l2, k, p, r, t
    """
    labels = list(df)
    filters = []
    for key, value in iteritems(kwargs):
        if key in labels:
            filters.append(df[key] == value)
    if filters:
        finalFilter = reduce(and_, filters)
        return df.loc[finalFilter]
    else:
        return df
    
def transformFrameToReal(dataframe):
    """ Transforms the given dataframe to the real spherical harmonic basis.
    """
    grouped = dataframe.groupby(['k','p','r', 'atom', 'species','nu', 'l1', 'l2'])
    realList = []
    for name, group in grouped:
        newGroup = transformGroupToReal(group)
        realList.append(newGroup)
    realdf = pd.concat(realList)<commit_msg>added deprecation warnings to old spherical real transformation<commit_after>import pandas as pd
import numpy as np
from operator import and_
from six import iteritems
from functools import reduce
import warnings


def transformGroupToReal(dataframe):
    """ Takes a dataframe and transforms the groups in it to a real representation.

    Args:
        dataframe:

    Returns:
        A copy of the old dataframe, containing the transformed elements.

    """
    warnings.warn("Use new transformation transform_group_to_real", DeprecationWarning  )
    mult = len(dataframe)
    l = int((mult-1)/2)
    newDataframe = dataframe.copy()
    for m in range(-l,l+1):        
        valPositive = dataframe.loc[dataframe.t == m, 'value'].values[0]
        valNegative = dataframe.loc[dataframe.t == -m, 'value'].values[0]
        if m < 0:                        
            newValue = (valPositive - ((-1)**m) *valNegative) * 1j/np.sqrt(2)            
        elif m > 0:
            newValue = (valNegative + ((-1)**m) * valPositive) * 1./np.sqrt(2)
        else:
            newValue = valPositive          
        newDataframe.loc[newDataframe.t == m, "value"] = newValue    
    return newDataframe


def filterTmoms(df, **kwargs):
    """ Returns all tensor moments to which the filter arguments in kwargs apply.
        Keys are: atom, species, nu, l1, l2, k, p, r, t
    """
    labels = list(df)
    filters = []
    for key, value in iteritems(kwargs):
        if key in labels:
            filters.append(df[key] == value)
    if filters:
        finalFilter = reduce(and_, filters)
        return df.loc[finalFilter]
    else:
        return df


def transformFrameToReal(dataframe):
    """ Transforms the given dataframe to the real spherical harmonic basis.
    """
    warnings.warn("Use new transformation function transform_to_real", DeprecationWarning)

    grouped = dataframe.groupby(['k','p','r', 'atom', 'species','nu', 'l1', 'l2'])
    realList = []
    for name, group in grouped:
        newGroup = transformGroupToReal(group)
        realList.append(newGroup)
    realdf = pd.concat(realList)
{'fraction_non_alphanumeric': 0.11261261261261261, 'fraction_numerical': 0.00850850850850851, 'mean_word_length': 2.4756521739130433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '734299', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1161, 'n_words': 359}