Best Python code snippet using pandera_python
test_schema_statistics.py
Source:test_schema_statistics.py
...362 [pd.Series(["foo", "bar"]), UserWarning],363 [pd.DataFrame({"column": ["foo", "bar"]}), UserWarning],364 ],365)366def test_infer_index_statistics(index, expectation):367 """Test that index statistics are correctly inferred."""368 if expectation is UserWarning:369 with pytest.warns(UserWarning, match="^index type .+ not recognized"):370 schema_statistics.infer_index_statistics(index)371 else:372 _test_statistics(373 schema_statistics.infer_index_statistics(index), expectation374 )375def test_get_dataframe_schema_statistics():376 """Test that dataframe schema statistics logic is correct."""377 schema = pa.DataFrameSchema(378 columns={379 "int": pa.Column(380 int,381 checks=[382 pa.Check.greater_than_or_equal_to(0),383 pa.Check.less_than_or_equal_to(100),384 ],385 nullable=True,386 ),387 "float": pa.Column(...
schema_statistics.py
Source:schema_statistics.py
...18 for col, dtype in inferred_column_dtypes.items()19 }20 return {21 "columns": column_statistics if column_statistics else None,22 "index": infer_index_statistics(df.index),23 }24def infer_series_statistics(series: pd.Series) -> Dict[str, Any]:25 """Infer column and index statistics from a pandas Series."""26 dtype = _get_array_type(series)27 return {28 "dtype": dtype,29 "nullable": bool(series.isna().any()),30 "checks": _get_array_check_statistics(series, dtype),31 "name": series.name,32 }33def infer_index_statistics(index: Union[pd.Index, pd.MultiIndex]):34 """Infer index statistics given a pandas Index object."""35 def _index_stats(index_level):36 dtype = _get_array_type(index_level)37 return {38 "dtype": dtype,39 "nullable": bool(index_level.isna().any()),40 "checks": _get_array_check_statistics(index_level, dtype),41 "name": index_level.name,42 }43 if isinstance(index, pd.MultiIndex):44 index_statistics = [45 _index_stats(index.get_level_values(i))46 for i in range(index.nlevels)47 ]...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!