Callback called from ``Aligner`` to create a new reindexed Dataset.
(
self,
aligner: alignment.Aligner,
dim_pos_indexers: dict[Hashable, Any],
variables: dict[Hashable, Variable],
indexes: dict[Hashable, Index],
fill_value: Any,
exclude_dims: frozenset[Hashable],
exclude_vars: frozenset[Hashable],
)
| 3360 | return _broadcast_helper(args[1], exclude, dims_map, common_coords) |
| 3361 | |
| 3362 | def _reindex_callback( |
| 3363 | self, |
| 3364 | aligner: alignment.Aligner, |
| 3365 | dim_pos_indexers: dict[Hashable, Any], |
| 3366 | variables: dict[Hashable, Variable], |
| 3367 | indexes: dict[Hashable, Index], |
| 3368 | fill_value: Any, |
| 3369 | exclude_dims: frozenset[Hashable], |
| 3370 | exclude_vars: frozenset[Hashable], |
| 3371 | ) -> Self: |
| 3372 | """Callback called from ``Aligner`` to create a new reindexed Dataset.""" |
| 3373 | |
| 3374 | new_variables = variables.copy() |
| 3375 | new_indexes = indexes.copy() |
| 3376 | |
| 3377 | # re-assign variable metadata |
| 3378 | for name, new_var in new_variables.items(): |
| 3379 | var = self._variables.get(name) |
| 3380 | if var is not None: |
| 3381 | new_var.attrs = var.attrs |
| 3382 | new_var.encoding = var.encoding |
| 3383 | |
| 3384 | # pass through indexes from excluded dimensions |
| 3385 | # no extra check needed for multi-coordinate indexes, potential conflicts |
| 3386 | # should already have been detected when aligning the indexes |
| 3387 | for name, idx in self._indexes.items(): |
| 3388 | var = self._variables[name] |
| 3389 | if set(var.dims) <= exclude_dims: |
| 3390 | new_indexes[name] = idx |
| 3391 | new_variables[name] = var |
| 3392 | |
| 3393 | if not dim_pos_indexers: |
| 3394 | # fast path for no reindexing necessary |
| 3395 | if set(new_indexes) - set(self._indexes): |
| 3396 | # this only adds new indexes and their coordinate variables |
| 3397 | reindexed = self._overwrite_indexes(new_indexes, new_variables) |
| 3398 | else: |
| 3399 | reindexed = self.copy(deep=aligner.copy) |
| 3400 | else: |
| 3401 | to_reindex = { |
| 3402 | k: v |
| 3403 | for k, v in self.variables.items() |
| 3404 | if k not in variables and k not in exclude_vars |
| 3405 | } |
| 3406 | reindexed_vars = alignment.reindex_variables( |
| 3407 | to_reindex, |
| 3408 | dim_pos_indexers, |
| 3409 | copy=aligner.copy, |
| 3410 | fill_value=fill_value, |
| 3411 | sparse=aligner.sparse, |
| 3412 | ) |
| 3413 | new_variables.update(reindexed_vars) |
| 3414 | new_coord_names = self._coord_names | set(new_indexes) |
| 3415 | reindexed = self._replace_with_new_dims( |
| 3416 | new_variables, new_coord_names, indexes=new_indexes |
| 3417 | ) |
| 3418 | |
| 3419 | reindexed.encoding = self.encoding |
nothing calls this directly
no test coverage detected