Exemplo n.º 1
0
def test_happy_scale_features():
    """Happy path test for testing `scale_features`"""
    test_data, columns = create_data()

    columns_to_encode = ['genres', 'parent_platforms']
    columns_to_drop = [
        'name', 'genres', 'parent_platforms', 'stores', 'background_image',
        'released'
    ]

    test_data.genres = test_data.genres.apply(
        lambda x: test_featurize_helpers.get_genres(x))
    test_data.parent_platforms = test_data.parent_platforms.apply(
        lambda x: test_featurize_helpers.get_platforms(x))

    # encode features
    output_data, intermediate_data = test_featurize_helpers.encode_features(
        test_data,
        columns_to_encode=columns_to_encode,
        columns_to_drop=columns_to_drop)

    scaled_output = test_featurize_helpers.scale_features(output_data)

    # check datatype, shape and column names
    test1 = (type(scaled_output).__module__ == np.__name__)
    test2 = (scaled_output.shape[0] == test_data.shape[0])
    assert (test1 and test2)
Exemplo n.º 2
0
def test_happy_encode_features():
    """Happy path test for testing `encode_features`"""
    test_data, columns = create_data()

    test_data.genres = test_data.genres.apply(
        lambda x: test_featurize_helpers.get_genres(x))
    test_data.parent_platforms = test_data.parent_platforms.apply(
        lambda x: test_featurize_helpers.get_platforms(x))

    columns_to_encode = ['genres', 'parent_platforms']
    columns_to_drop = [
        'name', 'genres', 'parent_platforms', 'stores', 'background_image',
        'released'
    ]
    #encode features
    output_data, intermediate_data = test_featurize_helpers.encode_features(
        test_data,
        columns_to_encode=columns_to_encode,
        columns_to_drop=columns_to_drop)

    # check datatype, shape and column names

    test1 = isinstance(output_data, pd.DataFrame)
    test2 = (output_data.shape[0] == test_data.shape[0])
    test3 = np.any(test_data.columns.isin(columns_to_encode))
    test4 = np.any(test_data.columns.isin(columns_to_drop))
    assert (test1 and test2 and test3 and test4)
Exemplo n.º 3
0
def test_unhappy_get_platfroms():
    """Unhappy path test for testing `get_platforms` with adding missing data"""
    test_data, columns = create_data()

    test_data = test_data.append(pd.Series(dtype='object'), ignore_index=True)

    output_data = test_data.copy()

    # create feature
    with pytest.raises(SystemExit):
        output_data.parent_platforms = test_data.parent_platforms.\
            apply(lambda x: test_featurize_helpers.get_platforms(x))
        assert output_data.parent_platforms is None
Exemplo n.º 4
0
def test_happy_get_platfroms():
    """Happy path test for testing `get_platforms`"""
    test_data, columns = create_data()

    # create feature
    output_platforms = test_data.parent_platforms.apply(
        lambda x: test_featurize_helpers.get_platforms(x))

    # check datatype, shape and column names
    test1 = (output_platforms.dtype == 'object')
    test2 = (output_platforms.shape[0] == test_data.shape[0])
    test3 = np.any(test_data.columns.isin(['parent_platforms']))
    test4 = ('parent_platforms' == output_platforms.name)

    assert (test1 and test2 and test3 and test4)
Exemplo n.º 5
0
def test_unhappy_scale_features():
    """UnHappy path test for testing `scale_features`,by giving dropping giving a categorical variable as well"""
    test_data, columns = create_data()

    test_data.genres = test_data.genres.apply(
        lambda x: test_featurize_helpers.get_genres(x))
    test_data.parent_platforms = test_data.parent_platforms.apply(
        lambda x: test_featurize_helpers.get_platforms(x))

    columns_to_encode = ['genres', 'parent_platforms']

    #haven't dropped name
    columns_to_drop = [
        'genres', 'parent_platforms', 'stores', 'background_image', 'released'
    ]
    # encode features
    output_data, intermediate_data = test_featurize_helpers.encode_features(
        test_data,
        columns_to_encode=columns_to_encode,
        columns_to_drop=columns_to_drop)
    #name has been included to be scaled
    with pytest.raises(SystemExit):
        output_scaled = test_featurize_helpers.scale_features(output_data)
        assert output_scaled is None
Exemplo n.º 6
0
def test_unhappy_encode_features():
    """UnHappy path test for testing `encode_features`,by dropping columns to encode"""
    test_data, columns = create_data()

    test_data.genres = test_data.genres.apply(
        lambda x: test_featurize_helpers.get_genres(x))
    test_data.parent_platforms = test_data.parent_platforms.apply(
        lambda x: test_featurize_helpers.get_platforms(x))

    columns_to_encode = None

    columns_to_drop = [
        'name', 'genres', 'parent_platforms', 'stores', 'background_image',
        'released'
    ]

    # create feature
    with pytest.raises(SystemExit):
        output_data, intermediate_data = test_featurize_helpers.encode_features(
            test_data,
            columns_to_encode=columns_to_encode,
            columns_to_drop=columns_to_drop)
        assert output_data is None
        assert intermediate_data is None