[docs]classSchema(collections.abc.Mapping):""" A source data schema proxy. It allows to work with source schema in a frozen-dict manner. It also allows to set using the ``set`` and update a source schema using the ``update`` methods. """dict_cls=dictdef__init__(self,_base_source=None,_hidden_columns=None,**kwargs):self._dict=self.dict_cls(**kwargs)self._base_source=_base_sourceself._hash=Noneself._hidden_columns=_hidden_columnsif_hidden_columnselse{}def__getitem__(self,item):ifisinstance(item,list):return{key:valueforkey,valueinself._dict.items()ifkeyinitem}ifiteminself._hidden_columns:returnself._hidden_columns[item]returnself._dict[item]def__setitem__(self,key,value):self.update(**{key:value})def__contains__(self,item):ifiteminself._hidden_columns:returnTruereturniteminself._dictdef__iter__(self):returniter(self._dict)
[docs]defset(self,**new_schema:type):""" Drops the python schema representation of a source and sets the new one from the `new_schema` Parameters ---------- new_schema: Dict[str, type] schema in the column-name -> type format Returns ------- None """self._base_source.set_schema(**new_schema)
[docs]defupdate(self,**other_schema:type):""" Updates the python schema representation of a source: values from matching keys will be overridden from the `other_schema`, values from new keys will be added. Parameters ---------- other_schema: schema in the column-name -> type format Returns ------- None """current_schema=self._base_source.columns(skip_meta_fields=True)current_schema.update(other_schema)self._base_source.set_schema(**current_schema)