|
34 | 34 | from ..utils.logger import logger |
35 | 35 |
|
36 | 36 | # NB: non-registered data components and extensions will not be found by loader |
37 | | -KNOWN_DATA_COMPONENTS = ["x", "y"] |
| 37 | +KNOWN_DATA_COMPONENTS = ["x", "y", "y_cls", "y_reg"] |
38 | 38 | KNOWN_DATA_EXTENSIONS = ["parq", "npz", "csr.npz"] |
39 | 39 |
|
40 | 40 |
|
41 | 41 | def get_expr_by_prefix(prefix: str) -> str: |
42 | 42 | def get_or_expr_from_list(a: List[str]) -> str: |
43 | 43 | # transforms list to OR expression: "['x', 'y']" -> "x|y" |
44 | | - return str(a)[1:-1].replace("'", "").replace(", ", "|") |
| 44 | + return "|".join(re.escape(item) for item in a) |
45 | 45 |
|
46 | 46 | data_comp_expr = get_or_expr_from_list(KNOWN_DATA_COMPONENTS) |
47 | 47 | data_ext_expr = get_or_expr_from_list(KNOWN_DATA_EXTENSIONS) |
48 | 48 |
|
49 | | - return f"{prefix}_({data_comp_expr}).({data_ext_expr})" |
| 49 | + return f"^{re.escape(prefix)}_({data_comp_expr})\\.({data_ext_expr})$" |
50 | 50 |
|
51 | 51 |
|
52 | 52 | def get_filenames_by_prefix(directory: str, prefix: str) -> List[str]: |
@@ -141,6 +141,27 @@ def save_data_description(data_desc: Dict, data_cache: str, data_name: str): |
141 | 141 | json.dump(data_desc, desc_file) |
142 | 142 |
|
143 | 143 |
|
| 144 | +""" |
| 145 | +This function is needed to avoid storing the dataset two times if |
| 146 | +it's used for both classification and regression tasks (e.g. airline_deepdelay) |
| 147 | +""" |
| 148 | + |
| 149 | + |
| 150 | +def task_dispatch(function): |
| 151 | + def task_dispatch_wrapper(**kwargs): |
| 152 | + data, data_desc = function(**kwargs) |
| 153 | + dataset_params = kwargs.get("dataset_params", dict()) |
| 154 | + task = dataset_params.get("task", "classification") |
| 155 | + if task == "classification": |
| 156 | + return {"x": data["x"], "y": data["y_cls"]}, data_desc |
| 157 | + elif task == "regression": |
| 158 | + return {"x": data["x"], "y": data["y_reg"]}, data_desc |
| 159 | + else: |
| 160 | + raise ValueError(f'Unknown "{task}" task type for airline dataset.') |
| 161 | + |
| 162 | + return task_dispatch_wrapper |
| 163 | + |
| 164 | + |
144 | 165 | def cache(function): |
145 | 166 | def cache_wrapper(**kwargs): |
146 | 167 | data_name = kwargs["data_name"] |
|
0 commit comments