How to use _format_groupby_input method in pandera

Best Python code snippet using pandera_python

checks.py

Source:checks.py Github

copy

Full Screen

...238 def statistics(self, statistics):239 """Set check statistics."""240 self._statistics = statistics241 @staticmethod242 def _format_groupby_input(243 groupby_obj: GroupbyObject,244 groups: Optional[List[str]],245 ) -> Union[Dict[str, Union[pd.Series, pd.DataFrame]]]:246 """Format groupby object into dict of groups to Series or DataFrame.247 :param groupby_obj: a pandas groupby object.248 :param groups: only include these groups in the output.249 :returns: dictionary mapping group names to Series or DataFrame.250 """251 if groups is None:252 return dict(list(groupby_obj))253 group_keys = set(group_key for group_key, _ in groupby_obj)254 invalid_groups = [g for g in groups if g not in group_keys]255 if invalid_groups:256 raise KeyError(257 f"groups {invalid_groups} provided in `groups` argument not a valid group "258 f"key. Valid group keys: {group_keys}"259 )260 return {261 group_key: group262 for group_key, group in groupby_obj263 if group_key in groups264 }265 def _prepare_series_input(266 self,267 df_or_series: Union[pd.Series, pd.DataFrame],268 column: Optional[str] = None,269 ) -> SeriesCheckObj:270 """Prepare input for Column check.271 :param pd.Series series: one-dimensional ndarray with axis labels272 (including time series).273 :param pd.DataFrame dataframe_context: optional dataframe to supply274 when checking a Column in a DataFrameSchema.275 :returns: a Series, or a dictionary mapping groups to Series276 to be used by `_check_fn` and `_vectorized_check`277 """278 if check_utils.is_field(df_or_series):279 return df_or_series280 elif self.groupby is None:281 return df_or_series[column]282 elif isinstance(self.groupby, list):283 return self._format_groupby_input(284 df_or_series.groupby(self.groupby)[column],285 self.groups,286 )287 elif callable(self.groupby):288 return self._format_groupby_input(289 self.groupby(df_or_series)[column],290 self.groups,291 )292 raise TypeError("Type %s not recognized for `groupby` argument.")293 def _prepare_dataframe_input(294 self, dataframe: pd.DataFrame295 ) -> DataFrameCheckObj:296 """Prepare input for DataFrameSchema check.297 :param dataframe: dataframe to validate.298 :returns: a DataFrame, or a dictionary mapping groups to pd.DataFrame299 to be used by `_check_fn` and `_vectorized_check`300 """301 if self.groupby is None:302 return dataframe303 groupby_obj = dataframe.groupby(self.groupby)304 return self._format_groupby_input(groupby_obj, self.groups)305 def __call__(306 self,307 df_or_series: Union[pd.DataFrame, pd.Series],308 column: Optional[str] = None,309 ) -> CheckResult:310 # pylint: disable=too-many-branches311 """Validate pandas DataFrame or Series.312 :param df_or_series: pandas DataFrame of Series to validate.313 :param column: for dataframe checks, apply the check function to this314 column.315 :returns: CheckResult tuple containing:316 ``check_output``: boolean scalar, ``Series`` or ``DataFrame``317 indicating which elements passed the check.318 ``check_passed``: boolean scalar that indicating whether the check...

Full Screen

Full Screen

hypotheses.py

Source:hypotheses.py Github

copy

Full Screen

...164 )165 if self.is_one_sample_test:166 return dataframe[self.samples[0]]167 check_obj = [(sample, dataframe[sample]) for sample in self.samples]168 return self._format_groupby_input(check_obj, self.samples)169 def _relationships(self, relationship: Union[str, Callable]):170 """Impose a relationship on a supplied Test function.171 :param relationship: represents what relationship conditions are172 imposed on the hypothesis test. A function or lambda function can173 be supplied. If a string is provided, a lambda function will be174 returned from Hypothesis.relationships. Available relationships175 are: "greater_than", "less_than", "not_equal"176 """177 if isinstance(relationship, str):178 if relationship not in self.RELATIONSHIPS:179 raise errors.SchemaInitError(180 f"The relationship {relationship} isn't a built in method"181 )182 relationship = self.RELATIONSHIPS[relationship]...

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