(indexes: Indexes[Index], args: Mapping[Any, Any], func: str)
| 2148 | |
| 2149 | |
| 2150 | def _apply_indexes_fast(indexes: Indexes[Index], args: Mapping[Any, Any], func: str): |
| 2151 | # This function avoids the call to indexes.group_by_index |
| 2152 | # which is really slow when repeatedly iterating through |
| 2153 | # an array. However, it fails to return the correct ID for |
| 2154 | # multi-index arrays |
| 2155 | indexes_fast, coords = indexes._indexes, indexes._variables |
| 2156 | |
| 2157 | new_indexes: dict[Hashable, Index] = dict(indexes_fast.items()) |
| 2158 | new_index_variables: dict[Hashable, Variable] = {} |
| 2159 | for name, index in indexes_fast.items(): |
| 2160 | coord = coords[name] |
| 2161 | if hasattr(coord, "_indexes"): |
| 2162 | index_vars = {n: coords[n] for n in coord._indexes} |
| 2163 | else: |
| 2164 | index_vars = {name: coord} |
| 2165 | index_dims = {d for var in index_vars.values() for d in var.dims} |
| 2166 | index_args = {k: v for k, v in args.items() if k in index_dims} |
| 2167 | |
| 2168 | if index_args: |
| 2169 | new_index = getattr(index, func)(index_args) |
| 2170 | if new_index is not None: |
| 2171 | new_indexes.update(dict.fromkeys(index_vars, new_index)) |
| 2172 | if new_index is index: |
| 2173 | new_index_vars = index_vars |
| 2174 | else: |
| 2175 | new_index_vars = new_index.create_variables(index_vars) |
| 2176 | new_index_variables.update(new_index_vars) |
| 2177 | else: |
| 2178 | for k in index_vars: |
| 2179 | new_indexes.pop(k, None) |
| 2180 | return new_indexes, new_index_variables |
| 2181 | |
| 2182 | |
| 2183 | def _apply_indexes( |
no test coverage detected
searching dependent graphs…