Esempio n. 1
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.core.implementations.types import (
        visions_generic,
        visions_string,
        visions_integer,
        visions_object,
    )

    relations = [
        IdentityRelation(visions_bool, visions_generic),
        InferenceRelation(
            visions_bool,
            visions_string,
            relationship=lambda s: coercion_map_test(cls.string_coercions)(
                s.str.lower()
            ),
            transformer=lambda s: to_bool(
                coercion_map(cls.string_coercions)(s.str.lower())
            ),
        ),
        InferenceRelation(
            visions_bool,
            visions_integer,
            relationship=lambda s: s.isin({0, 1, np.nan}).all(),
            transformer=to_bool,
        ),
        InferenceRelation(
            visions_bool,
            visions_object,
            relationship=lambda s: s.apply(type).isin([type(None), bool]).all(),
            transformer=to_bool,
        ),
    ]
    return relations
Esempio n. 2
0
def _get_relations(cls) -> List[TypeRelation]:
    from visions.types import Generic

    relations = [
        IdentityRelation(cls, Generic),
        InferenceRelation(
            cls,
            String,
            relationship=lambda s: coercion_map_test(cls.string_coercions)
            (s.str.lower()),
            transformer=lambda s: to_category(
                coercion_map(cls.string_coercions)(s.str.lower())),
        ),
        InferenceRelation(
            cls,
            Integer,
            relationship=lambda s: s.isin({0, 1, np.nan}).all(),
            transformer=to_category,
        ),
        InferenceRelation(
            cls,
            Object,
            relationship=lambda s: s.apply(type).isin([type(None), bool]).all(
            ),
            transformer=to_category,
        ),
    ]
    return relations
Esempio n. 3
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.types import Generic, Object, String

    relations = [
        IdentityRelation(cls, Generic),
        InferenceRelation(
            cls,
            String,
            relationship=lambda s: coercion_map_test(cls.string_coercions)
            (s.str.lower()),
            transformer=lambda s: to_bool(
                coercion_map(cls.string_coercions)(s.str.lower())),
        ),
        InferenceRelation(cls,
                          Object,
                          relationship=object_is_bool,
                          transformer=to_bool),
    ]
    return relations
def string_to_bool(series, state: dict, string_coercions):
    try:
        return to_bool(
            coercion_map(string_coercions)(series.str.lower()), state)
    except:
        return False