Checks if serialized_input_data will be of sparse format after deserialization. If there are uneven ids for scenarios in the serialized input, that would result in sparse data
(serialized_input_data, component)
| 118 | |
| 119 | |
| 120 | def is_sparse_data_input(serialized_input_data, component): |
| 121 | """Checks if serialized_input_data will be of sparse format after deserialization. |
| 122 | If there are uneven ids for scenarios in the serialized input, that would result in sparse data""" |
| 123 | if not serialized_input_data["is_batch"]: |
| 124 | raise ValueError("Checking if a non batch data is sparse") |
| 125 | |
| 126 | all_scenarios_ids: list[set[int]] = list(set()) |
| 127 | for scenario in serialized_input_data["data"]: |
| 128 | scenario_ids = set() |
| 129 | if component not in scenario: |
| 130 | continue |
| 131 | for scenario_comp_name_comp_idx in scenario[component]: |
| 132 | if is_non_compact_list(scenario_comp_name_comp_idx): |
| 133 | scenario_ids.add(scenario_comp_name_comp_idx[AT.id]) |
| 134 | else: |
| 135 | id_attr_idx = serialized_input_data["attributes"][component].index(AT.id) |
| 136 | scenario_ids.add(scenario_comp_name_comp_idx[id_attr_idx]) |
| 137 | all_scenarios_ids.append(scenario_ids) |
| 138 | first_scenario_ids = next(iter(all_scenarios_ids)) |
| 139 | |
| 140 | return any(first_scenario_ids != scenario_ids for scenario_ids in all_scenarios_ids) |
| 141 | |
| 142 | |
| 143 | def empty_dataset(dataset_type: DatasetType = DatasetType.input): |
no test coverage detected