tenzing.core.models.model_relation

class tenzing.core.models.model_relation(model, friend_model, relationship=None, transformer=None)

Relationship encoder between implementations of tenzing.core.models.tenzing_model

Defines a one to one relationship between two tenzing_model 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.

>>> x = pd.Series([1.0, 2.0, 3.0])
>>> relation = model_relation(tenzing_integer, tenzing_float)
>>> relation.is_relation(x)
True
>>> relation.transform(x)
pd.Series([1, 2, 3])
Parameters:
  • model (tenzing_type) – The type this relation will transform a series into.
  • friend_model (tenzing_type) – The type this relation will transform a series from.
  • relationship (func) – A method to determine if a series of friend_model type can be converted to type model.
  • transformer (func) – A method to convert a series from type friend_model to type model.
__init__(model, friend_model, relationship=None, transformer=None)

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

Methods

__init__(model, friend_model[, …]) Initialize self.
is_relation(obj)
transform(obj)