How to use _try_coercion method in pandera

Best Python code snippet using pandera_python

schemas.py

Source:schemas.py Github

copy

Full Screen

...323 :param obj: dataframe to coerce.324 :returns: dataframe with coerced dtypes325 """326 error_handler = SchemaErrorHandler(lazy=True)327 def _try_coercion(coerce_fn, obj):328 try:329 return coerce_fn(obj)330 except errors.SchemaError as exc:331 error_handler.collect_error("dtype_coercion_error", exc)332 return obj333 for colname, col_schema in self.columns.items():334 if col_schema.regex:335 try:336 matched_columns = col_schema.get_regex_columns(obj.columns)337 except errors.SchemaError:338 matched_columns = pd.Index([])339 for matched_colname in matched_columns:340 if col_schema.coerce or self.coerce:341 obj[matched_colname] = _try_coercion(342 col_schema.coerce_dtype, obj[matched_colname]343 )344 elif (345 (col_schema.coerce or self.coerce)346 and self.dtype is None347 and colname in obj348 ):349 obj[colname] = _try_coercion(350 col_schema.coerce_dtype, obj[colname]351 )352 if self.dtype is not None:353 obj = _try_coercion(self._coerce_dtype, obj)354 if self.index is not None and (self.index.coerce or self.coerce):355 index_schema = copy.deepcopy(self.index)356 if self.coerce:357 # coercing at the dataframe-level should apply index coercion358 # for both single- and multi-indexes.359 index_schema._coerce = True360 coerced_index = _try_coercion(index_schema.coerce_dtype, obj.index)361 if coerced_index is not None:362 obj.index = coerced_index363 if error_handler.collected_errors:364 raise errors.SchemaErrors(error_handler.collected_errors, obj)365 return obj366 def validate(367 self,368 check_obj: pd.DataFrame,369 head: Optional[int] = None,370 tail: Optional[int] = None,371 sample: Optional[int] = None,372 random_state: Optional[int] = None,373 lazy: bool = False,374 inplace: bool = False,...

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