How to use _to_checklist method in pandera

Best Python code snippet using pandera_python

model_components.py

Source:model_components.py Github

copy

Full Screen

...25SchemaComponent = TypeVar("SchemaComponent", bound=SeriesSchemaBase)26CHECK_KEY = "__check_config__"27DATAFRAME_CHECK_KEY = "__dataframe_check_config__"28_CheckList = Union[Check, List[Check]]29def _to_checklist(checks: Optional[_CheckList]) -> List[Check]:30 checks = checks or []31 if isinstance(checks, Check): # pragma: no cover32 return [checks]33 return checks34class FieldInfo:35 """Captures extra information about a field.36 *new in 0.5.0*37 """38 __slots__ = (39 "checks",40 "nullable",41 "unique",42 "allow_duplicates",43 "coerce",44 "regex",45 "check_name",46 "alias",47 "original_name",48 "dtype_kwargs",49 "title",50 "description",51 )52 def __init__(53 self,54 checks: Optional[_CheckList] = None,55 nullable: bool = False,56 unique: bool = False,57 allow_duplicates: Optional[bool] = None,58 coerce: bool = False,59 regex: bool = False,60 alias: Any = None,61 check_name: Optional[bool] = None,62 dtype_kwargs: Optional[Dict[str, Any]] = None,63 title: Optional[str] = None,64 description: Optional[str] = None,65 ) -> None:66 self.checks = _to_checklist(checks)67 self.nullable = nullable68 self.unique = unique69 self.allow_duplicates = allow_duplicates70 self.coerce = coerce71 self.regex = regex72 self.alias = alias73 self.check_name = check_name74 self.original_name = cast(str, None) # always set by SchemaModel75 self.dtype_kwargs = dtype_kwargs76 self.title = title77 self.description = description78 @property79 def name(self) -> str:80 """Return the name of the field used in the DataFrame"""81 if self.alias is not None:82 return self.alias83 return self.original_name84 def __set_name__(self, owner: Type, name: str) -> None:85 self.original_name = name86 def __get__(self, instance: Any, owner: Type) -> str:87 return self.name88 def __str__(self):89 return f'{self.__class__}("{self.name}")'90 def __repr__(self):91 cls = self.__class__92 return (93 f'<{cls.__module__}.{cls.__name__}("{self.name}") '94 f"object at {hex(id(self))}>"95 )96 def __hash__(self):97 return str(self.name).__hash__()98 def __eq__(self, other):99 return self.name == other100 def __ne__(self, other):101 return self.name != other102 def __set__(self, instance: Any, value: Any) -> None: # pragma: no cover103 raise AttributeError(f"Can't set the {self.original_name} field.")104 def _to_schema_component(105 self,106 pandas_dtype: PandasDtypeInputTypes,107 component: Type[SchemaComponent],108 checks: _CheckList = None,109 **kwargs: Any,110 ) -> SchemaComponent:111 if self.dtype_kwargs:112 pandas_dtype = pandas_dtype(**self.dtype_kwargs) # type: ignore113 checks = self.checks + _to_checklist(checks)114 return component(pandas_dtype, checks=checks, **kwargs) # type: ignore115 def to_column(116 self,117 pandas_dtype: PandasDtypeInputTypes,118 checks: _CheckList = None,119 required: bool = True,120 name: str = None,121 ) -> Column:122 """Create a schema_components.Column from a field."""123 return self._to_schema_component(124 pandas_dtype,125 Column,126 nullable=self.nullable,127 unique=self.unique,...

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