Пример #1
0
def NestedMappingField(cls,
                       keyword,
                       key,
                       default=NOTHING,
                       required=True,
                       repr=False):
    """
    Create new sequence field on a model. If only string is present,
    convert it to a list of length 1.

    :param cls: class (or name) of the model to be related in Sequence.
    :param keyword: stopping condition in recursion (indicator that cls has been found)
    :param key: key field on the child object to be used as the mapping key.
    :param default: any TypedSequence or list
    :param bool required: whether or not the object is invalid if not provided.
    :param bool repr: include this field should appear in object's repr.
    :param bool cmp: include this field in generated comparison.
    """
    default = _init_fields.init_default(required, default, OrderedDict())
    # check that it's not sequence
    converter = to_leaf_mapping_field(cls, keyword, key)
    # validator = _init_fields.init_validator(required, types.TypedSequence)
    validator = None
    return attrib(default=default,
                  convert=converter,
                  validator=validator,
                  repr=repr)
Пример #2
0
def AnyField(default=NOTHING, required=True, repr=True):
    """
    Just pass through the field, using default yaml conversion to python objects

    :param cls: class (or name) of the model to be related in Sequence.
    :param default: any TypedSequence or list
    :param bool required: whether or not the object is invalid if not provided.
    :param bool repr: include this field should appear in object's repr.
    :param bool cmp: include this field in generated comparison.
    """
    default = _init_fields.init_default(required, default, UNSPECIFIED())
    return attrib(default=default, convert=None, validator=None, repr=repr)
Пример #3
0
def TupleIntField(default=NOTHING, required=True, repr=True):
    """
    Create new tuple field on a model. Convert it first to a string
    and then to a tuple

    :param cls: class (or name) of the model to be related in Sequence.
    :param default: any TypedSequence or list
    :param bool required: whether or not the object is invalid if not provided.
    :param bool repr: include this field should appear in object's repr.
    :param bool cmp: include this field in generated comparison.
    """
    default = _init_fields.init_default(required, default, tuple)
    converter = to_eval_str
    validator = _init_fields.init_validator(required, tuple)
    return attrib(default=default, converter=converter, validator=validator,
              repr=repr)
Пример #4
0
def StrSequenceField(cls, default=NOTHING, required=True, repr=True):
    """
    Create new sequence field on a model. If only string is present,
    convert it to a list of length 1.

    :param cls: class (or name) of the model to be related in Sequence.
    :param default: any TypedSequence or list
    :param bool required: whether or not the object is invalid if not provided.
    :param bool repr: include this field should appear in object's repr.
    :param bool cmp: include this field in generated comparison.
    """
    default = _init_fields.init_default(required, default, [])
    # check that it's not sequence
    converter = to_sequence_field_w_str(cls)
    validator = _init_fields.init_validator(required, types.TypedSequence)
    return attrib(default=default,
                  convert=converter,
                  validator=validator,
                  repr=repr)
def TimeDelta(default=NOTHING, required=True, repr=True, cmp=True, key=None):
    """
    Create new bool field on a model.
    :param default: any timedelta string
    :param bool required: whether or not the object is invalid if not provided.
    :param bool repr: include this field should appear in object's repr.
    :param bool cmp: include this field in generated comparison.
    :param string key: override name of the value when converted to dict.
    """
    default = _init_fields.init_default(required, default, None)
    validator = _init_fields.init_validator(
        required, pd._libs.tslibs.timedeltas.Timedelta)
    converter = pd.to_timedelta
    return attrib(default=default,
                  converter=converter,
                  validator=validator,
                  repr=repr,
                  cmp=cmp,
                  metadata=dict(key=key))