<commit_before>__author__ = 'mfitzp'

import pandas as pd
import numpy as np

def remove_columns_matching(df, column, match):
    df = df.copy()
    mask = df[column].values != match
    return df.iloc[mask, :]


def remove_columns_containing(df, column, match):
    df = df.copy()
    mask = [match not in str(v) for v in df[column].values]
    return df.iloc[mask, :]


def remove_reverse(df):
    """
    Remove rows with a + in the 'Reverse' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Reverse', '+')


def remove_potential_contaminants(df):
    """
    Remove rows with a + in the 'Contaminants' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Potential contaminant', '+')


def remove_only_identified_by_site(df):
    """
    Remove rows with a + in the 'Only identified by site' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Only identified by site', '+')


def filter_localization_probability(df, threshold=0.75):
    """
    Remove rows with a localization probability below 0.75

    :param df: Pandas dataframe
    :param threshold: Cut-off below which rows are discarded (default 0.75)
    :return: Pandas dataframe
    """
    df = df.copy()
    localization_probability_mask = df['Localization prob'].values >= threshold
    return df.iloc[localization_probability_mask, :]


def minimum_valid_values_in_group(df, levels, n=1, invalid=np.nan):
    """
    Filter dataframe by at least n valid values in at least one group.
    
    """

    # Filter by at least 7 (values in class:timepoint) at least in at least one group
    if invalid is np.nan:
        dfx = ~np.isnan(df)<commit_msg>Change name of at least n in any group function<commit_after>__author__ = 'mfitzp'

import pandas as pd
import numpy as np

def remove_columns_matching(df, column, match):
    df = df.copy()
    mask = df[column].values != match
    return df.iloc[mask, :]


def remove_columns_containing(df, column, match):
    df = df.copy()
    mask = [match not in str(v) for v in df[column].values]
    return df.iloc[mask, :]


def remove_reverse(df):
    """
    Remove rows with a + in the 'Reverse' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Reverse', '+')


def remove_potential_contaminants(df):
    """
    Remove rows with a + in the 'Contaminants' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Potential contaminant', '+')


def remove_only_identified_by_site(df):
    """
    Remove rows with a + in the 'Only identified by site' column

    :param df: Pandas dataframe
    :return: Pandas dataframe
    """
    return remove_columns_containing(df, 'Only identified by site', '+')


def filter_localization_probability(df, threshold=0.75):
    """
    Remove rows with a localization probability below 0.75

    :param df: Pandas dataframe
    :param threshold: Cut-off below which rows are discarded (default 0.75)
    :return: Pandas dataframe
    """
    df = df.copy()
    localization_probability_mask = df['Localization prob'].values >= threshold
    return df.iloc[localization_probability_mask, :]


def minimum_valid_values_in_any_group(df, levels, n=1, invalid=np.nan):
    """
    Filter dataframe by at least n valid values in at least one group.
    
    """

    # Filter by at least 7 (values in class:timepoint) at least in at least one group
    if invalid is np.nan:
        dfx = ~np.isnan(df)
{'fraction_non_alphanumeric': 0.10309278350515463, 'fraction_numerical': 0.005968529571351058, 'mean_word_length': 3.442168674698795, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '467776', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1130, 'n_words': 368}