def test_autoclean_cv_with_nans_with_strings():
    data = pd.DataFrame({'A': np.random.rand(1000),
                         'B': np.random.rand(1000),
                         'C': np.random.randint(0, 3, 1000)})

    string_map = {0: 'oranges', 1: 'apples', 2: 'bananas'}
    data['C'] = data['C'].apply(lambda x: string_map[x])

    training_data = data[:500].copy()
    testing_data = data[500:].copy()

    training_data.loc[10:20, 'A'] = np.nan
    training_data.loc[50:70, 'C'] = np.nan

    testing_data.loc[70:80, 'A'] = np.nan
    testing_data.loc[10:40, 'C'] = np.nan

    hand_cleaned_training_data = training_data.copy()
    hand_cleaned_testing_data = testing_data.copy()

    training_A_median = hand_cleaned_training_data['A'].median()
    training_C_mode = hand_cleaned_training_data['C'].mode()[0]
    hand_cleaned_training_data['A'].fillna(training_A_median, inplace=True)
    hand_cleaned_training_data['C'].fillna(training_C_mode, inplace=True)

    hand_cleaned_testing_data['A'].fillna(training_A_median, inplace=True)
    hand_cleaned_testing_data['C'].fillna(training_C_mode, inplace=True)

    encoder = LabelEncoder()
    hand_cleaned_training_data['C'] = encoder.fit_transform(hand_cleaned_training_data['C'].values)
    hand_cleaned_testing_data['C'] = encoder.transform(hand_cleaned_testing_data['C'].values)

    cleaned_training_data, cleaned_testing_data = autoclean_cv(training_data, testing_data)

    assert cleaned_training_data.equals(hand_cleaned_training_data)
    assert cleaned_testing_data.equals(hand_cleaned_testing_data)
Test autoclean_cv() with a data set that has some string-encoded categorical values and some NaNs
dataset/ETHPy150Open rhiever/datacleaner/tests.py/test_autoclean_cv_with_nans_with_strings