visions.relations.relations.TypeRelation

class visions.relations.relations.TypeRelation(type, related_type, inferential, transformer, relationship=<function TypeRelation.<lambda>>)[source]

Relationship encoder between implementations of visions.types.type.VisionsBaseType

Defines a one to one relationship between two VisionsBaseType implementations, A and B, with respect to an underlying data series. In order to define a relationship we need two methods:

  • is_relationship, determines whether a series of type B can be alternatively represented as type A.

  • transform, provides a mechanism to convert the series from B -> A.

For example, the series pd.Series([1.0, 2.0, 3.0]) is encoded as a sequence of floats but in reality they are all integers.

Examples

>>> from visions.types import Integer, Float
>>> x = pd.Series([1.0, 2.0, 3.0])
>>> relation = TypeRelation(Integer, Float)
>>> relation.is_relation(x)
True
>>> relation.transform(x)
pd.Series([1, 2, 3])
__init__(type, related_type, inferential, transformer, relationship=<function TypeRelation.<lambda>>)

Initialize self. See help(type(self)) for accurate signature.

Return type

None

Methods

__init__(type, related_type, inferential, …)

Initialize self.

is_relation(series)

rtype

bool

transform(series)

rtype

Series