How to use _check_source_dtype method in pandera

Best Python code snippet using pandera_python

engine.py

Source:engine.py Github

copy

Full Screen

...58 def dtype(data_type: Any) -> DataType:59 raise ValueError(f"Data type '{data_type}' not understood")60 cls._registry[engine] = _DtypeRegistry(dispatch=dtype, equivalents={})61 return engine62 def _check_source_dtype(cls, data_type: Any) -> None:63 if isinstance(data_type, cls._base_pandera_dtypes) or (64 inspect.isclass(data_type)65 and issubclass(data_type, cls._base_pandera_dtypes)66 ):67 base_names = [68 f"{base.__module__}.{base.__qualname__}"69 for base in cls._base_pandera_dtypes70 ]71 raise ValueError(72 f"Subclasses of {base_names} cannot be registered"73 f" with {cls.__name__}."74 )75 def _register_from_parametrized_dtype(76 cls,77 pandera_dtype_cls: Type[DataType],78 ) -> None:79 method = pandera_dtype_cls.__dict__["from_parametrized_dtype"]80 if not isinstance(method, classmethod):81 raise ValueError(82 f"{pandera_dtype_cls.__name__}.from_parametrized_dtype "83 + "must be a classmethod."84 )85 func = method.__func__86 annotations = get_type_hints(func).values()87 dtype = next(iter(annotations)) # get 1st annotation88 # parse typing.Union89 dtypes = typing_inspect.get_args(dtype) or [dtype]90 def _method(*args, **kwargs):91 return func(pandera_dtype_cls, *args, **kwargs)92 for source_dtype in dtypes:93 cls._check_source_dtype(source_dtype)94 cls._registry[cls].dispatch.register(source_dtype, _method)95 def _register_equivalents(96 cls, pandera_dtype_cls: Type[DataType], *source_dtypes: Any97 ) -> None:98 pandera_dtype = pandera_dtype_cls() # type: ignore99 for source_dtype in source_dtypes:100 cls._check_source_dtype(source_dtype)101 cls._registry[cls].equivalents[source_dtype] = pandera_dtype102 def register_dtype(103 cls: _EngineType,104 pandera_dtype_cls: Type[_DataType] = None,105 *,106 equivalents: Optional[List[Any]] = None,107 ) -> Callable:108 """Register a Pandera :class:`~pandera.dtypes.DataType` with the engine,109 as class decorator.110 :param pandera_dtype: The DataType to register.111 :param equivalents: Equivalent scalar data type classes or112 non-parametrized data type instances.113 .. note::114 The classmethod ``from_parametrized_dtype`` will also be...

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