|
7 | 7 |
|
8 | 8 | def get_check_data_type_function(data_type): |
9 | 9 | if data_type == "INTEGER": |
10 | | - py_data_types = [int] |
| 10 | + return [int], __check_data_type_integer |
11 | 11 | elif data_type == "FLOAT": |
12 | | - py_data_types = [int, float] |
| 12 | + return [int, float], __check_data_type_float |
13 | 13 | elif data_type == "BOOLEAN": |
14 | | - py_data_types = [bool] |
| 14 | + return [bool], __check_data_type_boolean |
15 | 15 | elif data_type == "CATEGORY": |
16 | | - py_data_types = [str] |
| 16 | + return [str], __check_data_type_category |
17 | 17 | elif data_type == "TEXT": |
18 | | - py_data_types = [str] |
| 18 | + return [str], __check_data_type_text |
19 | 19 | else: |
20 | 20 | raise ValueError(f"Unknown data type: {data_type}") |
21 | | - return py_data_types, lambda f: any( |
22 | | - [isinstance(f, py_data_type) for py_data_type in py_data_types] |
23 | | - ) |
| 21 | + |
| 22 | + |
| 23 | +def __check_data_type_integer(attr_value): |
| 24 | + if attr_value is not None and not isinstance(attr_value, int): |
| 25 | + return False |
| 26 | + return True |
| 27 | + |
| 28 | + |
| 29 | +def __check_data_type_float(attr_value): |
| 30 | + if ( |
| 31 | + attr_value is not None |
| 32 | + and not isinstance(attr_value, float) |
| 33 | + and not isinstance(attr_value, int) |
| 34 | + ): |
| 35 | + return False |
| 36 | + return True |
| 37 | + |
| 38 | + |
| 39 | +def __check_data_type_boolean(attr_value): |
| 40 | + if not isinstance(attr_value, bool): |
| 41 | + return False |
| 42 | + return True |
| 43 | + |
| 44 | + |
| 45 | +def __check_data_type_category(attr_value): |
| 46 | + if not isinstance(attr_value, str): |
| 47 | + return False |
| 48 | + if attr_value == "": |
| 49 | + raise ValueError("Category cannot be empty string") |
| 50 | + return True |
| 51 | + |
| 52 | + |
| 53 | +def __check_data_type_text(attr_value): |
| 54 | + if not isinstance(attr_value, str): |
| 55 | + return False |
| 56 | + return True |
24 | 57 |
|
25 | 58 |
|
26 | 59 | def load_data_dict(record): |
|
0 commit comments