Пример #1
0
def test_type_system_default_type(default_inference_functions, default_relationships):
    type_sys = TypeSystem(inference_functions=default_inference_functions,
                          relationships=default_relationships,
                          default_type=SubRegionCode)
    assert type_sys.default_type == SubRegionCode
    type_sys.update_inference_function(Categorical, None)
    test_series = pd.Series(['a', 'b', 'c'])
    assert type_sys.infer_logical_type(test_series) == SubRegionCode
    assert SubRegionCode in type_sys.registered_types
Пример #2
0
def test_inference_multiple_matches_different_depths(default_relationships):
    def always_true(series):
        return True
    inference_functions = {
        Categorical: always_true,
        Double: always_true,
        Integer: always_true,
        CountryCode: always_true,
    }
    type_sys = TypeSystem(inference_functions=inference_functions,
                          relationships=default_relationships,
                          default_type=NaturalLanguage)
    type_sys.update_inference_function(Integer, always_true)
    type_sys.update_inference_function(CountryCode, always_true)
    type_sys.add_type(SubRegionCode, inference_function=always_true, parent=CountryCode)
    inferred_type = type_sys.infer_logical_type(pd.Series([1, 2, 3]))
    # Should match SubRegionCode as it is the deepest match
    assert inferred_type == SubRegionCode
Пример #3
0
def test_inference_multiple_matches_same_depth(default_relationships):
    def always_true(series):
        return True
    inference_functions = {
        Categorical: always_true,
        Double: always_true,
        Integer: always_true,
        CountryCode: always_true,
    }
    type_sys = TypeSystem(inference_functions=inference_functions,
                          relationships=default_relationships,
                          default_type=NaturalLanguage)
    type_sys.update_inference_function(Integer, always_true)
    type_sys.update_inference_function(CountryCode, always_true)
    inferred_type = type_sys.infer_logical_type(pd.Series([1, 2, 3]))
    # Should match CountryCode - same depth as Integer, but CountryCode parent
    # (Categorical) is tried and found first
    assert inferred_type == CountryCode