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
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
def string_to_ordinal(cls) -> InferenceRelation: from visions.core.implementations.types import visions_string return InferenceRelation(cls, visions_string, relationship=is_ordinal_str, transformer=to_ordinal)
def categorical_to_ordinal(cls) -> InferenceRelation: from visions.core.implementations.types import visions_categorical return InferenceRelation(cls, visions_categorical, relationship=is_ordinal_cat, transformer=to_ordinal)
def integer_to_count(): return InferenceRelation( relationship=is_unsigned_int, transformer=lambda s: s.astype(np.uint64), type=visions_integer, related_type=visions_count, )
def get_string_datetime_type_relation(func): return InferenceRelation( relationship=test_utils.coercion_test(func), transformer=func, related_type=visions_string, type=visions_datetime, )
def integer_to_datetime_year_month_day(cls): return InferenceRelation( relationship=test_utils.coercion_test( lambda s: to_datetime_year_month_day(s.astype(str))), transformer=to_datetime, type=visions_datetime, related_type=cls, )
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
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
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
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
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
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
def string_to_categorical_distinct_count(cls) -> TypeRelation: """Convert string to categorical when it has fewer than 50% unique values. Returns: relation """ # TODO: only when not any other string relation (either exclude others or have ordering and evaluate last) return InferenceRelation( relationship=lambda s: s.nunique() / len(s) < 0.5, transformer=lambda s: s.astype("category"), related_type=visions_string, type=cls, )
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
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