How to use _parse_schema_errors method in pandera

Best Python code snippet using pandera_python

errors.py

Source:errors.py Github

copy

Full Screen

...108 self,109 schema_errors: List[Dict[str, Any]],110 data: Union[pd.Series, pd.DataFrame],111 ):112 error_counts, failure_cases = self._parse_schema_errors(schema_errors)113 super().__init__(self._message(error_counts, failure_cases))114 self.schema_errors = schema_errors115 self.error_counts = error_counts116 self.failure_cases = failure_cases117 self.data = data118 @staticmethod119 def _message(error_counts, schema_errors):120 """Format error message."""121 msg = (122 f"A total of {sum(error_counts.values())} "123 "schema errors were found.\n"124 )125 msg += "\nError Counts"126 msg += "\n------------\n"127 for k, v in error_counts.items():128 msg += f"- {k}: {v}\n"129 def agg_failure_cases(df):130 # NOTE: this is a hack to add modin support131 if type(df).__module__.startswith("modin.pandas"):132 return (133 df.groupby(["schema_context", "column", "check"])134 .agg({"failure_case": "unique"})135 .failure_case136 )137 return df.groupby(138 ["schema_context", "column", "check"]139 ).failure_case.unique()140 agg_schema_errors = (141 schema_errors.fillna({"column": "<NA>"})142 .pipe(agg_failure_cases)143 .rename("failure_cases")144 .to_frame()145 .assign(n_failure_cases=lambda df: df.failure_cases.map(len))146 )147 index_labels = [148 agg_schema_errors.index.names.index(name)149 for name in ["schema_context", "column"]150 ]151 agg_schema_errors = agg_schema_errors.sort_index(152 level=index_labels,153 ascending=[False, True],154 )155 msg += "\nSchema Error Summary"156 msg += "\n--------------------\n"157 with pd.option_context("display.max_colwidth", 100):158 msg += agg_schema_errors.to_string()159 msg += SCHEMA_ERRORS_SUFFIX160 return msg161 @staticmethod162 def _parse_schema_errors(schema_errors: List[Dict[str, Any]]):163 """Parse schema error dicts to produce data for error message."""164 error_counts = defaultdict(int) # type: ignore165 check_failure_cases = []166 column_order = [167 "schema_context",168 "column",169 "check",170 "check_number",171 "failure_case",172 "index",173 ]174 for schema_error_dict in schema_errors:175 reason_code = schema_error_dict["reason_code"]176 err = schema_error_dict["error"]...

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