|
1 | 1 | """Class-based API for Ibis models.""" |
2 | 2 |
|
| 3 | +import sys |
3 | 4 | import inspect |
4 | | -from typing import Dict, List, Tuple |
| 5 | +from typing import ( |
| 6 | + Dict, |
| 7 | + List, |
| 8 | + Tuple, |
| 9 | + Type, |
| 10 | + Optional, |
| 11 | + cast, |
| 12 | +) |
5 | 13 |
|
6 | 14 | import ibis |
7 | 15 | import ibis.expr.datatypes as dt |
8 | 16 |
|
| 17 | +from pandera.api.base.schema import BaseSchema |
9 | 18 | from pandera.api.checks import Check |
10 | 19 | from pandera.api.dataframe.model import DataFrameModel as _DataFrameModel |
11 | 20 | from pandera.api.dataframe.model import get_dtype_kwargs |
|
15 | 24 | from pandera.engines import ibis_engine |
16 | 25 | from pandera.errors import SchemaInitError |
17 | 26 | from pandera.typing import AnnotationInfo |
| 27 | +from pandera.typing.ibis import Table |
| 28 | +from pandera.utils import docstring_substitution |
| 29 | + |
| 30 | + |
| 31 | +# if python version is < 3.11, import Self from typing_extensions |
| 32 | +if sys.version_info < (3, 11): |
| 33 | + from typing_extensions import Self |
| 34 | +else: |
| 35 | + from typing import Self |
18 | 36 |
|
19 | 37 |
|
20 | 38 | class DataFrameModel(_DataFrameModel[ibis.Table, DataFrameSchema]): |
@@ -102,3 +120,21 @@ def _build_columns( # pylint:disable=too-many-locals |
102 | 120 | ) |
103 | 121 |
|
104 | 122 | return columns |
| 123 | + |
| 124 | + @classmethod |
| 125 | + @docstring_substitution(validate_doc=BaseSchema.validate.__doc__) |
| 126 | + def validate( |
| 127 | + cls: Type[Self], |
| 128 | + check_obj: ibis.Table, |
| 129 | + head: Optional[int] = None, |
| 130 | + tail: Optional[int] = None, |
| 131 | + sample: Optional[int] = None, |
| 132 | + random_state: Optional[int] = None, |
| 133 | + lazy: bool = False, |
| 134 | + inplace: bool = False, |
| 135 | + ) -> Table[Self]: |
| 136 | + """%(validate_doc)s""" |
| 137 | + result = cls.to_schema().validate( |
| 138 | + check_obj, head, tail, sample, random_state, lazy, inplace |
| 139 | + ) |
| 140 | + return cast(Table[Self], result) |
0 commit comments