Beispiel #1
0
def register_integer_relations():
    relations = [
        IdentityRelation(visions_integer, visions_generic),
        InferenceRelation(
            visions_integer,
            visions_float,
            test_utils.coercion_equality_test(lambda s: s.astype(int)),
        ),
        InferenceRelation(
            visions_integer,
            visions_float,
            test_utils.coercion_equality_test(lambda s: s.astype("Int64")),
        ),
        InferenceRelation(
            visions_integer,
            visions_string,
            test_utils.coercion_test(lambda s: s.astype(int)),
        ),
        InferenceRelation(
            visions_integer,
            visions_string,
            test_utils.coercion_test(
                lambda s: pd.to_numeric(s).astype("Int64")),
        ),
    ]

    return relations
Beispiel #2
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
Beispiel #3
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_string, visions_object

    relations = [
        IdentityRelation(cls, visions_object),
        InferenceRelation(
            cls, visions_string, relationship=test_uuid, transformer=to_uuid
        ),
    ]
    return relations
Beispiel #4
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_generic

    relations = [
        IdentityRelation(visions_datetime, visions_generic),
        InferenceRelation(
            visions_datetime,
            visions_string,
            relationship=test_utils.coercion_test(to_datetime),
            transformer=to_datetime,
        ),
    ]
    return relations
Beispiel #5
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_object, visions_string

    relations = [
        IdentityRelation(cls, visions_object),
        InferenceRelation(
            cls,
            visions_string,
            relationship=test_utils.coercion_test(to_ip),
            transformer=to_ip,
        ),
    ]
    return relations
Beispiel #6
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_object, visions_string

    relations = [
        IdentityRelation(visions_path, visions_object),
        InferenceRelation(
            visions_path,
            visions_string,
            relationship=string_is_path,
            transformer=to_path,
        ),
    ]
    return relations
Beispiel #7
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_generic, visions_string

    relations = [
        IdentityRelation(cls, visions_generic),
        InferenceRelation(
            cls,
            visions_string,
            relationship=test_string_is_complex,
            transformer=to_complex,
        ),
    ]
    return relations
Beispiel #8
0
def register_bool_relations():
    # Nullable bool: Object - > Bool
    class string_bool_relation:
        _boolean_maps = [
            {"true": True, "false": False},
            {"y": True, "n": False},
            {"yes": True, "no": False},
        ]

        def __init__(self):
            self._full_boolean_map = {
                k: v for d in self._boolean_maps for k, v in d.items()
            }

        # TODO: ensure that series.str.lower() has no side effects
        def string_is_bool(self, series):
            temp_series = series.str.lower()
            return any(
                temp_series.isin(boolean_map.keys()).all()
                for boolean_map in self._boolean_maps
            )

        def map_string_to_bool(self, series):
            return series.str.lower().map(self._full_boolean_map)

    sb_relation = string_bool_relation()
    relations = [
        IdentityRelation(visions_bool, visions_generic),
        InferenceRelation(
            visions_bool,
            visions_string,
            sb_relation.string_is_bool,
            sb_relation.map_string_to_bool,
        ),
        InferenceRelation(
            visions_bool,
            visions_object,
            test_utils.coercion_equality_test(
                lambda s: pd.to_numeric(s).astype("Bool")
            ),
        ),
    ]
    return relations
Beispiel #9
0
def _get_relations(cls) -> List[TypeRelation]:
    from visions.core.implementations.types import (
        visions_string,
        visions_generic,
        visions_float,
    )

    relations = [
        IdentityRelation(cls, visions_generic),
        InferenceRelation(cls,
                          visions_float,
                          relationship=float_is_int,
                          transformer=to_int),
        InferenceRelation(
            cls,
            visions_string,
            relationship=test_utils.coercion_test(to_int),
            transformer=to_int,
        ),
    ]
    return relations
Beispiel #10
0
def _get_relations(cls) -> Sequence[TypeRelation]:
    from visions.core.implementations.types import (
        visions_generic,
        visions_string,
        visions_complex,
    )

    relations = [
        IdentityRelation(cls, visions_generic),
        InferenceRelation(cls,
                          visions_string,
                          relationship=test_string_is_float,
                          transformer=to_float),
        InferenceRelation(
            cls,
            visions_complex,
            relationship=lambda s: all(np.imag(s.values) == 0),
            transformer=suppress_warnings(to_float),
        ),
    ]
    return relations
Beispiel #11
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_datetime

    relations = [IdentityRelation(visions_date, visions_datetime)]
    return relations
Beispiel #12
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_object

    relations = [IdentityRelation(visions_string, visions_object)]
    return relations
Beispiel #13
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_path

    relations = [IdentityRelation(visions_existing_path, visions_path)]
    return relations
Beispiel #14
0
 def get_relations(cls):
     return [IdentityRelation(visions_binary, visions_nominal)]
Beispiel #15
0
def _get_relations(cls) -> List[TypeRelation]:
    from visions.core.implementations.types import visions_generic

    relations = [IdentityRelation(cls, visions_generic)]
    return relations
Beispiel #16
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_generic

    relations = [IdentityRelation(visions_timedelta, visions_generic)]
    return relations
Beispiel #17
0
def _get_relations() -> Sequence[TypeRelation]:
    from visions.core.implementations.types import visions_categorical

    relations = [IdentityRelation(visions_ordinal, visions_categorical)]
    return relations
Beispiel #18
0
 def get_relations(cls):
     return [IdentityRelation(visions_ratio, visions_interval)]
Beispiel #19
0
 def get_relations(cls):
     return [IdentityRelation(visions_interval, visions_generic)]
Beispiel #20
0
 def get_relations(cls):
     return [IdentityRelation(visions_ordinal, visions_generic)]