How to use _collect_fields method in pandera

Best Python code snippet using pandera_python

mapping.py

Source:mapping.py Github

copy

Full Screen

...26 return super(Properties, self).to_dict()['properties']27 def field(self, name, *args, **kwargs):28 self.properties[name] = construct_field(*args, **kwargs)29 return self30 def _collect_fields(self):31 """ Iterate over all Field objects within, including multi fields. """32 for f in itervalues(self.properties.to_dict()):33 yield f34 # multi fields35 if hasattr(f, 'fields'):36 for inner_f in itervalues(f.fields.to_dict()):37 yield inner_f38 # nested and inner objects39 if hasattr(f, '_collect_fields'):40 for inner_f in f._collect_fields():41 yield inner_f42 def update(self, other_object):43 if not hasattr(other_object, 'properties'):44 # not an inner/nested object, no merge possible45 return46 our, other = self.properties, other_object.properties47 for name in other:48 if name in our:49 if hasattr(our[name], 'update'):50 our[name].update(other[name])51 continue52 our[name] = other[name]53class Mapping(object):54 def __init__(self):55 self.properties = Properties()56 self._meta = {}57 def __repr__(self):58 return 'Mapping()'59 def _clone(self):60 m = Mapping()61 m.properties._params = self.properties._params.copy()62 return m63 @classmethod64 def from_es(cls, index, using='default'):65 m = cls()66 m.update_from_es(index, using)67 return m68 def resolve_nested(self, field_path):69 field = self70 nested = []71 parts = field_path.split('.')72 for i, step in enumerate(parts):73 try:74 field = field[step]75 except KeyError:76 return (), None77 if isinstance(field, Nested):78 nested.append('.'.join(parts[:i+1]))79 return nested, field80 def resolve_field(self, field_path):81 field = self82 for step in field_path.split('.'):83 try:84 field = field[step]85 except KeyError:86 return87 return field88 def _collect_analysis(self):89 analysis = {}90 fields = []91 if '_all' in self._meta:92 fields.append(Text(**self._meta['_all']))93 for f in chain(fields, self.properties._collect_fields()):94 for analyzer_name in ('analyzer', 'normalizer', 'search_analyzer', 'search_quote_analyzer'):95 if not hasattr(f, analyzer_name):96 continue97 analyzer = getattr(f, analyzer_name)98 d = analyzer.get_analysis_definition()99 # empty custom analyzer, probably already defined out of our control100 if not d:101 continue102 # merge the definition103 # TODO: conflict detection/resolution104 for key in d:105 analysis.setdefault(key, {}).update(d[key])106 return analysis107 def save(self, index, using='default'):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful