def test_binning_rules_sorts_bins():
    unsorted_bins = [
        shf.BinFactory(ge=30, lt=40),
        shf.BinFactory(ge=20, lt=25),
        shf.BinFactory(ge=25, lt=30),
    ]
    res = shf.BinningRulesFactory(bins=unsorted_bins)
    assert sorted([x.ge for x in unsorted_bins]) == [x.ge for x in res.bins]
Beispiel #2
0
def test_bin_interpolation_with_ovewritten_default(engine_result, final_result,
                                                   bins, aggregation):
    query = shf.GroupByQueryFactory(
        bin_interpolation=True,
        aggregations=[aggregation],
        groups=[
            shf.BinningAttributeFactory(
                alias=b,
                function_uri=shf.FunctionUriFactory(
                    function_type="group_by",
                    function_uid=attribute.GroupByFunction.NUMERIC_BINNING.uid,
                    function_params=shf.BinningRulesFactory(bins=bins[b]),
                ),
            ) for b in bins
        ],
    )
    assert final_result == utils.bin_interpolation(query, engine_result)
def test_binning_rules_raises_for_invalid_null_values(bins):
    err_msg = "null values found in prohibited properties"
    with pytest.raises(ValidationError, match=err_msg):
        shf.BinningRulesFactory(bins=bins)
def test_binning_rules_raises_for_insufficient_bins(bins):
    with pytest.raises(ValidationError):
        shf.BinningRulesFactory(bins=bins)
def test_binning_rules_accepts_holes_between_bins(bins):
    shf.BinningRulesFactory(bins=bins)
def test_binning_rules_raises_for_overlapping_values(bins):
    err_msg = "found overlapping bins"
    with pytest.raises(ValidationError, match=err_msg):
        shf.BinningRulesFactory(bins=bins)