(
self,
dim: Hashable,
index_and_vars: tuple[Index, dict[Hashable, Variable]],
fill_value,
sparse: bool = False,
)
| 5451 | return data_array |
| 5452 | |
| 5453 | def _unstack_once( |
| 5454 | self, |
| 5455 | dim: Hashable, |
| 5456 | index_and_vars: tuple[Index, dict[Hashable, Variable]], |
| 5457 | fill_value, |
| 5458 | sparse: bool = False, |
| 5459 | ) -> Self: |
| 5460 | index, index_vars = index_and_vars |
| 5461 | variables: dict[Hashable, Variable] = {} |
| 5462 | indexes = {k: v for k, v in self._indexes.items() if k != dim} |
| 5463 | |
| 5464 | new_indexes, clean_index = index.unstack() |
| 5465 | indexes.update(new_indexes) |
| 5466 | |
| 5467 | for idx in new_indexes.values(): |
| 5468 | variables.update(idx.create_variables(index_vars)) |
| 5469 | |
| 5470 | for name, var in self.variables.items(): |
| 5471 | if name not in index_vars: |
| 5472 | if dim in var.dims: |
| 5473 | if isinstance(fill_value, Mapping): |
| 5474 | fill_value_ = fill_value.get(name, xrdtypes.NA) |
| 5475 | else: |
| 5476 | fill_value_ = fill_value |
| 5477 | |
| 5478 | variables[name] = var._unstack_once( |
| 5479 | index=clean_index, |
| 5480 | dim=dim, |
| 5481 | fill_value=fill_value_, |
| 5482 | sparse=sparse, |
| 5483 | ) |
| 5484 | else: |
| 5485 | variables[name] = var |
| 5486 | |
| 5487 | coord_names = set(self._coord_names) - {dim} | set(new_indexes) |
| 5488 | |
| 5489 | return self._replace_with_new_dims( |
| 5490 | variables, coord_names=coord_names, indexes=indexes |
| 5491 | ) |
| 5492 | |
| 5493 | def _unstack_full_reindex( |
| 5494 | self, |
no test coverage detected