Exemplo n.º 1
0
def test_scale_to_targets_no_segments(df, target_col):
    target = [1000]
    metric = 'mean'

    result = scl.scale_to_targets(df, target_col, target, metric=metric)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(
        result[target_col],
        pd.Series(
            [181.81818182, 363.63636364, 545.45454545, 727.27272727,
             909.09090909, 1090.90909091, 1272.72727273, 1454.54545455,
             1636.36363636, 1818.18181818]),
        check_dtype=False)
Exemplo n.º 2
0
def test_scale_to_targets(df, target_col):
    targets = [100, 1000]
    filters = [['geo_id == "a"', 'filter_col < 106'], 'geo_id == "b"']
    metric = 'sum'

    result = scl.scale_to_targets(df, target_col, targets, metric, filters)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(
        result[target_col],
        pd.Series(
            [11.11111111, 66.66666667, 33.33333333, 133.33333333, 55.55555556,
             200, 7, 266.66666667, 9, 333.33333333]),
        check_dtype=False)
Exemplo n.º 3
0
def test_scale_to_targets_clip_int(df, target_col):
    target = [1000]
    metric = 'mean'
    clip_low = 400
    clip_high = 999.99
    int_result = True

    result = scl.scale_to_targets(
        df, target_col, target, metric, clip_low=clip_low, clip_high=clip_high,
        int_result=int_result)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(
        result[target_col],
        pd.Series([400, 400, 545, 727, 909, 1000, 1000, 1000, 1000, 1000]))
Exemplo n.º 4
0
def test_scale_to_targets_no_segments(df, target_col):
    target = [1000]
    metric = 'mean'

    result = scl.scale_to_targets(df, target_col, target, metric=metric)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(result[target_col],
                            pd.Series([
                                181.81818182, 363.63636364, 545.45454545,
                                727.27272727, 909.09090909, 1090.90909091,
                                1272.72727273, 1454.54545455, 1636.36363636,
                                1818.18181818
                            ]),
                            check_dtype=False)
Exemplo n.º 5
0
def test_scale_to_targets(df, target_col):
    targets = [100, 1000]
    filters = [['geo_id == "a"', 'filter_col < 106'], 'geo_id == "b"']
    metric = 'sum'

    result = scl.scale_to_targets(df, target_col, targets, metric, filters)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(result[target_col],
                            pd.Series([
                                11.11111111, 66.66666667, 33.33333333,
                                133.33333333, 55.55555556, 200, 7,
                                266.66666667, 9, 333.33333333
                            ]),
                            check_dtype=False)
Exemplo n.º 6
0
def test_scale_to_targets_clip_int(df, target_col):
    target = [1000]
    metric = 'mean'
    clip_low = 400
    clip_high = 999.99
    int_result = True

    result = scl.scale_to_targets(df,
                                  target_col,
                                  target,
                                  metric,
                                  clip_low=clip_low,
                                  clip_high=clip_high,
                                  int_result=int_result)

    pdt.assert_index_equal(result.columns, df.columns)
    pdt.assert_series_equal(
        result[target_col],
        pd.Series([400, 400, 545, 727, 909, 1000, 1000, 1000, 1000, 1000]))