Best Python code snippet using pandera_python
io.py
Source:io.py
...25 ) from exc26DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"27def _get_qualified_name(cls: type) -> str:28 return f"{cls.__module__}.{cls.__qualname__}"29def _serialize_check_stats(check_stats, dtype=None):30 """Serialize check statistics into json/yaml-compatible format."""31 def handle_stat_dtype(stat):32 if pandas_engine.Engine.dtype(dtypes.DateTime).check(33 dtype34 ) and hasattr(stat, "strftime"):35 # try serializing stat as a string if it's datetime-like,36 # otherwise return original value37 return stat.strftime(DATETIME_FORMAT)38 elif pandas_engine.Engine.dtype(dtypes.Timedelta).check(39 dtype40 ) and hasattr(stat, "delta"):41 # try serializing stat into an int in nanoseconds if it's42 # timedelta-like, otherwise return original value43 return stat.delta44 return stat45 # for unary checks, return a single value instead of a dictionary46 if len(check_stats) == 1:47 return handle_stat_dtype(list(check_stats.values())[0])48 # otherwise return a dictionary of keyword args needed to create the Check49 serialized_check_stats = {}50 for arg, stat in check_stats.items():51 serialized_check_stats[arg] = handle_stat_dtype(stat)52 return serialized_check_stats53def _serialize_dataframe_stats(dataframe_checks):54 """55 Serialize global dataframe check statistics into json/yaml-compatible56 format.57 """58 serialized_checks = {}59 for check_name, check_stats in dataframe_checks.items():60 # The case that `check_name` is not registered is handled in61 # `parse_checks` so we know that `check_name` exists.62 # infer dtype of statistics and serialize them63 serialized_checks[check_name] = _serialize_check_stats(check_stats)64 return serialized_checks65def _serialize_component_stats(component_stats):66 """67 Serialize column or index statistics into json/yaml-compatible format.68 """69 serialized_checks = None70 if component_stats["checks"] is not None:71 serialized_checks = {}72 for check_name, check_stats in component_stats["checks"].items():73 serialized_checks[check_name] = _serialize_check_stats(74 check_stats, component_stats["dtype"]75 )76 dtype = component_stats.get("dtype")77 if dtype:78 dtype = str(dtype)79 return {80 "dtype": dtype,81 "nullable": component_stats["nullable"],82 "checks": serialized_checks,83 **{84 key: component_stats.get(key)85 for key in [86 "name",87 "unique",...
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!!