How to use make_row_strategy method in pandera

Best Python code snippet using pandera_python

strategies.py

Source:strategies.py Github

copy

Full Screen

...846 "Falling back to filtering drawn values based on the check "847 "definition. This can considerably slow down data-generation."848 )849 return strategy.filter(check_fn)850 def make_row_strategy(col, checks):851 strategy = None852 for check in checks:853 if hasattr(check, "strategy"):854 strategy = check.strategy(col.dtype, strategy)855 else:856 strategy = undefined_check_strategy(857 strategy=(858 pandas_dtype_strategy(col.dtype)859 if strategy is None860 else strategy861 ),862 check=check,863 )864 if strategy is None:865 strategy = pandas_dtype_strategy(col.dtype)866 return strategy867 @composite868 def _dataframe_strategy(draw):869 row_strategy_checks = []870 undefined_strat_df_checks = []871 for check in checks:872 if hasattr(check, "strategy") or check.element_wise:873 # we can apply element-wise checks defined at the dataframe874 # level to the row strategy875 row_strategy_checks.append(check)876 else:877 undefined_strat_df_checks.append(check)878 # expand column set to generate column names for columns where879 # regex=True.880 expanded_columns = {}881 for col_name, column in columns.items():882 if unique and col_name in unique:883 # if the column is in the set of columns specified in `unique`,884 # make the column strategy independently unique. This is885 # technically stricter than it should be, since the list of886 # columns in `unique` are required to be jointly unique, but887 # this is a simple solution that produces synthetic data that888 # fulfills the uniqueness constraints of the dataframe.889 column = deepcopy(column)890 column.unique = True891 if not column.regex:892 expanded_columns[col_name] = column893 else:894 regex_columns = draw(895 st.lists(896 st.from_regex(column.name, fullmatch=True),897 min_size=n_regex_columns,898 max_size=n_regex_columns,899 unique=True,900 )901 )902 for regex_col in regex_columns:903 expanded_columns[regex_col] = deepcopy(column).set_name(904 regex_col905 )906 # collect all non-element-wise column checks with undefined strategies907 undefined_strat_column_checks: Dict[str, list] = defaultdict(list)908 for col_name, column in expanded_columns.items():909 undefined_strat_column_checks[col_name].extend(910 check911 for check in column.checks912 if not hasattr(check, "strategy") and not check.element_wise913 )914 # override the column datatype with dataframe-level datatype if915 # specified916 col_dtypes = {917 col_name: str(col.dtype)918 if pandera_dtype is None919 else str(pandera_dtype)920 for col_name, col in expanded_columns.items()921 }922 nullable_columns = {923 col_name: col.nullable924 for col_name, col in expanded_columns.items()925 }926 row_strategy = None927 if row_strategy_checks:928 row_strategy = st.fixed_dictionaries(929 {930 col_name: make_row_strategy(col, row_strategy_checks)931 for col_name, col in expanded_columns.items()932 }933 )934 strategy = pdst.data_frames(935 columns=[936 column.strategy_component()937 for column in expanded_columns.values()938 ],939 rows=row_strategy,940 index=pdst.range_indexes(941 min_size=0 if size is None else size, max_size=size942 ),943 )944 # this is a hack to convert np.str_ data values into native python str....

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