Skip to content

Commit 7dcccce

Browse files
committed
Add minimal xr.Variable handling to preprocess_and_wrap (xref Unidata#1464)
1 parent 2a28e5e commit 7dcccce

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/metpy/xarray.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,27 @@ def wrapper(*args, **kwargs):
10911091
arg_names_to_broadcast = tuple(
10921092
arg_name for arg_name in broadcast
10931093
if arg_name in bound_args.arguments
1094-
and isinstance(bound_args.arguments[arg_name], xr.DataArray)
1094+
and isinstance(
1095+
bound_args.arguments[arg_name],
1096+
(xr.DataArray, xr.Variable)
1097+
)
10951098
)
10961099
broadcasted_args = xr.broadcast(
10971100
*(bound_args.arguments[arg_name] for arg_name in arg_names_to_broadcast)
10981101
)
10991102
for i, arg_name in enumerate(arg_names_to_broadcast):
11001103
bound_args.arguments[arg_name] = broadcasted_args[i]
11011104

1105+
# Cast all Variables to their data and warn
1106+
# (need to do before match finding, since we don't want to rewrap as Variable)
1107+
for arg_name in bound_args.arguments:
1108+
if isinstance(bound_args.arguments[arg_name], xr.Variable):
1109+
warnings.warn(
1110+
f'Argument {arg_name} given as xarray Variable...casting to its data. '
1111+
'xarray DataArrays are recommended instead.'
1112+
)
1113+
bound_args.arguments[arg_name] = bound_args.arguments[arg_name].data
1114+
11021115
# Obtain proper match if referencing an input
11031116
match = list(wrap_like) if isinstance(wrap_like, tuple) else wrap_like
11041117
if isinstance(wrap_like, str):

0 commit comments

Comments
 (0)