You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing no data to the Dataset constructor can result in a very unhelpful "tuple index out of range" error when this is a clear case of malformed input that we should be able to catch.
What did you expect to happen?
An error more like "tuple must be of form (dims, data[, attrs])"
Minimal Complete Verifiable Example
xr.Dataset({"t": ()})
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
---------------------------------------------------------------------------IndexErrorTraceback (mostrecentcalllast)
CellIn[2], line1---->1xr.Dataset({"t": ()})
File~/Documents/Work/Code/xarray/xarray/core/dataset.py:693, inDataset.__init__(self, data_vars, coords, attrs)
690ifisinstance(coords, Dataset):
691coords=coords._variables-->693variables, coord_names, dims, indexes, _ =merge_data_and_coords(
694data_vars, coords695 )
697self._attrs=dict(attrs) ifattrselseNone698self._close=NoneFile~/Documents/Work/Code/xarray/xarray/core/dataset.py:422, inmerge_data_and_coords(data_vars, coords)
418coords=create_coords_with_default_indexes(coords, data_vars)
420# exclude coords from alignment (all variables in a Coordinates object should421# already be aligned together) and use coordinates' indexes to align data_vars-->422returnmerge_core(
423 [data_vars, coords],
424compat="broadcast_equals",
425join="outer",
426explicit_coords=tuple(coords),
427indexes=coords.xindexes,
428priority_arg=1,
429skip_align_args=[1],
430 )
File~/Documents/Work/Code/xarray/xarray/core/merge.py:718, inmerge_core(objects, compat, join, combine_attrs, priority_arg, explicit_coords, indexes, fill_value, skip_align_args)
715forpos, objinskip_align_objs:
716aligned.insert(pos, obj)
-->718collected=collect_variables_and_indexes(aligned, indexes=indexes)
719prioritized=_get_priority_vars_and_indexes(aligned, priority_arg, compat=compat)
720variables, out_indexes=merge_collected(
721collected, prioritized, compat=compat, combine_attrs=combine_attrs722 )
File~/Documents/Work/Code/xarray/xarray/core/merge.py:358, incollect_variables_and_indexes(list_of_mappings, indexes)
355indexes_.pop(name, None)
356append_all(coords_, indexes_)
-->358variable=as_variable(variable, name=name, auto_convert=False)
359ifnameinindexes:
360append(name, variable, indexes[name])
File~/Documents/Work/Code/xarray/xarray/core/variable.py:126, inas_variable(obj, name, auto_convert)
124obj=obj.copy(deep=False)
125elifisinstance(obj, tuple):
-->126ifisinstance(obj[1], DataArray):
127raiseTypeError(
128f"Variable {name!r}: Using a DataArray object to construct a variable is"129" ambiguous, please extract the data using the .data property."130 )
131try:
IndexError: tupleindexoutofrange
Anything else we need to know?
No response
Environment
Xarray main
The text was updated successfully, but these errors were encountered:
What happened?
Passing no data to the
Dataset
constructor can result in a very unhelpful "tuple index out of range" error when this is a clear case of malformed input that we should be able to catch.What did you expect to happen?
An error more like "tuple must be of form (dims, data[, attrs])"
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
Xarray
main
The text was updated successfully, but these errors were encountered: