Skip to content

Commit 36cee3a

Browse files
authored
Changes allowed return values for data types (#8)
* forbid empty string as return value for data type category * allow None as return value for float and integer attributes
1 parent 60f49e2 commit 36cee3a

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

run_ac.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,53 @@
77

88
def get_check_data_type_function(data_type):
99
if data_type == "INTEGER":
10-
py_data_types = [int]
10+
return [int], __check_data_type_integer
1111
elif data_type == "FLOAT":
12-
py_data_types = [int, float]
12+
return [int, float], __check_data_type_float
1313
elif data_type == "BOOLEAN":
14-
py_data_types = [bool]
14+
return [bool], __check_data_type_boolean
1515
elif data_type == "CATEGORY":
16-
py_data_types = [str]
16+
return [str], __check_data_type_category
1717
elif data_type == "TEXT":
18-
py_data_types = [str]
18+
return [str], __check_data_type_text
1919
else:
2020
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
2457

2558

2659
def load_data_dict(record):

0 commit comments

Comments
 (0)