def to_dict(self, validate=True, ignore=[], context={}): type_ = getattr(self, 'type', Undefined) if type_ is Undefined and 'data' in context: kwds = parse_shorthand_plus_data(self.field, context['data']) else: kwds = parse_shorthand(self.field) self._kwds.update(kwds) return super(Column, self).to_dict(validate=validate, ignore=ignore, context=context)
def to_dict(self, validate=True, ignore=(), context=None): context = context or {} condition = getattr(self, 'condition', Undefined) copy = self # don't copy unless we need to if condition is not Undefined: if isinstance(condition, core.SchemaBase): pass elif 'field' in condition and 'type' not in condition: kwds = parse_shorthand(condition['field'], context.get('data', None)) copy = self.copy() copy.condition.update(kwds) return super(ValueChannelMixin, copy).to_dict(validate=validate, ignore=ignore, context=context)
def to_dict(self, validate=True, ignore=(), context=None): context = context or {} condition = getattr(self, 'condition', Undefined) copy = self # don't copy unless we need to if condition is not Undefined: if isinstance(condition, core.SchemaBase): pass elif 'field' in condition and 'type' not in condition: kwds = parse_shorthand(condition['field'], context.get('data', None)) copy = self.copy() copy.condition.update(kwds) return super(ValueChannelMixin, copy).to_dict(validate=validate, ignore=ignore, context=context)
def to_dict(self, validate=True, ignore=(), context=None): type_ = getattr(self, 'type', Undefined) context = context or {} if not isinstance(self.field, six.string_types): # field is a RepeatSpec or similar; cannot infer type kwds = {} elif type_ is Undefined and 'data' in context: kwds = parse_shorthand_plus_data(self.field, context['data']) else: kwds = parse_shorthand(self.field) self._kwds.update(kwds) return super(Order, self).to_dict(validate=validate, ignore=ignore, context=context)
def to_dict(self, validate=True, ignore=(), context=None): context = context or {} if self.shorthand is Undefined: kwds = {} elif isinstance(self.shorthand, (tuple, list)): # If given a list of shorthands, then transform it to a list of classes kwds = self._kwds.copy() kwds.pop('shorthand') return [ self.__class__(shorthand, **kwds).to_dict() for shorthand in self.shorthand ] elif isinstance(self.shorthand, six.string_types): kwds = parse_shorthand(self.shorthand, data=context.get('data', None)) type_defined = self._kwds.get('type', Undefined) is not Undefined if not (type_defined or 'type' in kwds): if isinstance(context.get('data', None), pd.DataFrame): raise ValueError( "{} encoding field is specified without a type; " "the type cannot be inferred because it does not " "match any column in the data.".format(self.shorthand)) else: raise ValueError( "{} encoding field is specified without a type; " "the type cannot be automatically inferred because " "the data is not specified as a pandas.DataFrame." "".format(self.shorthand)) else: # shorthand is not a string; we pass the definition to field if self.field is not Undefined: raise ValueError("both shorthand and field specified in {}" "".format(self.__class__.__name__)) # field is a RepeatSpec or similar; cannot infer type kwds = {'field': self.shorthand} # set shorthand to Undefined, because it's not part of the schema self.shorthand = Undefined self._kwds.update({ k: v for k, v in kwds.items() if self._kwds.get(k, Undefined) is Undefined }) return super(FieldChannelMixin, self).to_dict(validate=validate, ignore=ignore, context=context)
def to_dict(self, validate=True, ignore=(), context=None): context = context or {} if self.shorthand is Undefined: kwds = {} elif isinstance(self.shorthand, (tuple, list)): # If given a list of shorthands, then transform it to a list of classes kwds = self._kwds.copy() kwds.pop('shorthand') return [self.__class__(shorthand, **kwds).to_dict() for shorthand in self.shorthand] elif isinstance(self.shorthand, six.string_types): kwds = parse_shorthand(self.shorthand, data=context.get('data', None)) type_defined = self._kwds.get('type', Undefined) is not Undefined if not (type_defined or 'type' in kwds): if isinstance(context.get('data', None), pd.DataFrame): raise ValueError("{} encoding field is specified without a type; " "the type cannot be inferred because it does not " "match any column in the data.".format(self.shorthand)) else: raise ValueError("{} encoding field is specified without a type; " "the type cannot be automatically inferred because " "the data is not specified as a pandas.DataFrame." "".format(self.shorthand)) else: # shorthand is not a string; we pass the definition to field if self.field is not Undefined: raise ValueError("both shorthand and field specified in {}" "".format(self.__class__.__name__)) # field is a RepeatSpec or similar; cannot infer type kwds = {'field': self.shorthand} # set shorthand to Undefined, because it's not part of the schema self.shorthand = Undefined self._kwds.update({k: v for k, v in kwds.items() if self._kwds.get(k, Undefined) is Undefined}) return super(FieldChannelMixin, self).to_dict( validate=validate, ignore=ignore, context=context )
def __init__(self, field, **kwargs): kwds = parse_shorthand(field) kwds.update(kwargs) super(Size, self).__init__(**kwds)