Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert new_shape from list to tuple in _unstack_once #5319

Merged
merged 1 commit into from
May 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ def _unstack_once(

# Potentially we could replace `len(other_dims)` with just `-1`
other_dims = [d for d in self.dims if d != dim]
new_shape = list(reordered.shape[: len(other_dims)]) + new_dim_sizes
new_shape = tuple(list(reordered.shape[: len(other_dims)]) + new_dim_sizes)
Copy link
Collaborator

@keewis keewis May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not worth a new PR, but if .shape is always a tuple this could be simplified to

Suggested change
new_shape = tuple(list(reordered.shape[: len(other_dims)]) + new_dim_sizes)
new_shape = reordered.shape[: len(other_dims)] + tuple(new_dim_sizes)

new_dims = reordered.dims[: len(other_dims)] + new_dim_names

if fill_value is dtypes.NA:
Expand All @@ -1592,7 +1592,6 @@ def _unstack_once(
else:
dtype = self.dtype

# Currently fails on sparse due to https://github.com/pydata/sparse/issues/422
data = np.full_like(
self.data,
fill_value=fill_value,
Expand All @@ -1603,6 +1602,8 @@ def _unstack_once(
# Indexer is a list of lists of locations. Each list is the locations
# on the new dimension. This is robust to the data being sparse; in that
# case the destinations will be NaN / zero.
# sparse doesn't support item assigment,
# https://github.com/pydata/sparse/issues/114
data[(..., *indexer)] = reordered

return self._replace(dims=new_dims, data=data)
Expand Down