Best Python code snippet using pandera_python
schema_components.py
Source:schema_components.py
...13 DataFrameSchema,14 PandasDtypeInputTypes,15 SeriesSchemaBase,16)17def _is_valid_multiindex_tuple_str(x: Tuple[Any, ...]) -> bool:18 """Check that a multi-index tuple key has all string elements"""19 return isinstance(x, tuple) and all(isinstance(i, str) for i in x)20class Column(SeriesSchemaBase):21 """Validate types and properties of DataFrame columns."""22 @deprecate_pandas_dtype23 def __init__(24 self,25 dtype: PandasDtypeInputTypes = None,26 checks: CheckList = None,27 nullable: bool = False,28 unique: bool = False,29 allow_duplicates: Optional[bool] = None,30 coerce: bool = False,31 required: bool = True,32 name: Union[str, Tuple[str, ...], None] = None,33 regex: bool = False,34 pandas_dtype: PandasDtypeInputTypes = None,35 title: Optional[str] = None,36 description: Optional[str] = None,37 ) -> None:38 """Create column validator object.39 :param dtype: datatype of the column. A ``PandasDtype`` for40 type-checking dataframe. If a string is specified, then assumes41 one of the valid pandas string values:42 http://pandas.pydata.org/pandas-docs/stable/basics.html#dtypes43 :param checks: checks to verify validity of the column44 :param nullable: Whether or not column can contain null values.45 :param unique: whether column values should be unique46 :param allow_duplicates: Whether or not column can contain duplicate47 values.48 .. warning::49 This option will be deprecated in 0.8.0. Use the ``unique``50 argument instead.51 :param coerce: If True, when schema.validate is called the column will52 be coerced into the specified dtype. This has no effect on columns53 where ``pandas_dtype=None``.54 :param required: Whether or not column is allowed to be missing55 :param name: column name in dataframe to validate.56 :param regex: whether the ``name`` attribute should be treated as a57 regex pattern to apply to multiple columns in a dataframe.58 :param pandas_dtype: alias of ``dtype`` for backwards compatibility.59 .. warning:: This option will be deprecated in 0.8.060 :param title: A human-readable label for the column.61 :param description: An arbitrary textual description of the column.62 :raises SchemaInitError: if impossible to build schema from parameters63 :example:64 >>> import pandas as pd65 >>> import pandera as pa66 >>>67 >>>68 >>> schema = pa.DataFrameSchema({69 ... "column": pa.Column(str)70 ... })71 >>>72 >>> schema.validate(pd.DataFrame({"column": ["foo", "bar"]}))73 column74 0 foo75 1 bar76 See :ref:`here<column>` for more usage details.77 """78 super().__init__(79 dtype,80 checks,81 nullable,82 unique,83 allow_duplicates,84 coerce,85 name,86 pandas_dtype,87 title,88 description,89 )90 if (91 name is not None92 and not isinstance(name, str)93 and not _is_valid_multiindex_tuple_str(name)94 and regex95 ):96 raise ValueError(97 "You cannot specify a non-string name when setting regex=True"98 )99 self.required = required100 self._name = name101 self._regex = regex102 @property103 def regex(self) -> bool:104 """True if ``name`` attribute should be treated as a regex pattern."""105 return self._regex106 @property107 def _allow_groupby(self) -> bool:...
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!!