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

Blogs

Check out the latest blogs from LambdaTest on this topic:

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

LIVE With Automation Testing For OTT Streaming Devices ????

People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.

Different Ways To Style CSS Box Shadow Effects

Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.

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