issues: 834509559
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
834509559 | MDU6SXNzdWU4MzQ1MDk1NTk= | 5051 | Error message when trying to concatenate DataSet and DataArray | 37740986 | closed | 0 | 4 | 2021-03-18T08:07:18Z | 2021-06-04T22:05:29Z | 2021-06-04T22:05:29Z | CONTRIBUTOR | I come from the conversation 5047. There is a misleading error when trying to concatenate a DataArray and a DataSet: What you expected to happen: Have an error that give you a hint about the wrong type Minimal Complete Verifiable Example: ```python import numpy as np import xarray as xr dataset = xr.Dataset( {"measurements": (("simulation", "characteristic", "value"), np.random.random((10,3,6)))}, coords={"characteristic": ['a', 'b', 'c']}) logged = np.log(dataset["measurements"].sel(characteristic=["b", "c"])) logged = logged.assign_coords(characteristic=["log_b", "log_c"]) xr.concat([dataset, logged], dim="characteristic")
ValueError Traceback (most recent call last) <ipython-input-10-8df5bd650bd4> in <module> 10 logged = logged.assign_coords(characteristic=["log_b", "log_c"]) 11 ---> 12 xr.concat([dataset, logged], dim="characteristic") C:\ProgramData\Anaconda3\lib\site-packages\xarray\core\concat.py in concat(objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs) 237 "objects, got %s" % type(first_obj) 238 ) --> 239 return f( 240 objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs 241 ) C:\ProgramData\Anaconda3\lib\site-packages\xarray\core\concat.py in _dataset_concat(datasets, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs) 433 ) 434 --> 435 dim_coords, dims_sizes, coord_names, data_names = _parse_datasets(datasets) 436 dim_names = set(dim_coords) 437 unlabeled_dims = dim_names - coord_names C:\ProgramData\Anaconda3\lib\site-packages\xarray\core\concat.py in _parse_datasets(datasets) 394 395 for ds in datasets: --> 396 dims_sizes.update(ds.dims) 397 all_coord_names.update(ds.coords) 398 data_vars.update(ds.data_vars) ValueError: dictionary update sequence element #0 has length 10; 2 is required ``` Anything else we need to know?:
For the previous code to be working, it is needed to write Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.8.8 (default, Feb 24 2021, 15:54:32) [MSC v.1928 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD byteorder: little LC_ALL: None LANG: None LOCALE: fr_FR.cp1252 libhdf5: 1.10.4 libnetcdf: None xarray: 0.17.0 pandas: 1.2.3 numpy: 1.19.2 scipy: 1.6.1 netCDF4: None pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: 2021.02.0 distributed: 2021.03.0 matplotlib: 3.3.4 cartopy: None seaborn: 0.11.1 numbagg: None pint: None setuptools: 52.0.0.post20210125 pip: 21.0.1 conda: 4.9.2 pytest: 6.2.2 IPython: 7.21.0 sphinx: 3.5.1 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5051/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |