Skip to content
Open
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
20 changes: 13 additions & 7 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,20 @@ def _check_core_dims(signature, variable_args, name):
# Check whether all the dims are on the variable. Note that we need the
# `hasattr` to check for a dims property, to protect against the case where
# a numpy array is passed in.
if hasattr(variable_arg, "dims") and set(core_dims) - set(variable_arg.dims):
missing += [[i, variable_arg, core_dims]]
if hasattr(variable_arg, "dims"):
missing_dims = set(core_dims) - set(variable_arg.dims)
if missing_dims:
missing.append((i, variable_arg, core_dims, missing_dims))
if missing:
message = ""
for i, variable_arg, core_dims in missing:
message += f"Missing core dims {set(core_dims) - set(variable_arg.dims)} from arg number {i + 1} on a variable named `{name}`:\n{variable_arg}\n\n"
message += "Either add the core dimension, or if passing a dataset alternatively pass `on_missing_core_dim` as `copy` or `drop`. "
return message
lines = []
for i, variable_arg, core_dims, missing_dims in missing:
lines.append(
f"Missing core dims {missing_dims} from arg number {i + 1} on a variable named `{name}`:\n{variable_arg}\n"
)
lines.append(
"Either add the core dimension, or if passing a dataset alternatively pass `on_missing_core_dim` as `copy` or `drop`. "
)
return "\n".join(lines)
return True


Expand Down