question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistency in whether index is created with new dimension coordinate?

See original GitHub issue

It seems like set_coords() doesn’t create an index variable. Is there a reason for this? I was surprised that the following code snippets produce different Datasets (first one has empty indexes, second one has x in indexes), even though both Datasets have a ‘dimension coordinate’ x:

(1)

import numpy as np
import xarray as xr

ds = xr.Dataset()
ds['a'] = ('x', np.linspace(0,1))
ds['b'] = ('x', np.linspace(3,4))
ds = ds.rename(b='x')
ds = ds.set_coords('x')

print(ds)
print('indexes', ds.indexes)

(2)

import numpy as np
import xarray as xr

ds = xr.Dataset()
ds['a'] = ('x', np.linspace(0,1))
ds['x'] = ('x', np.linspace(3,4))

print(ds)
print('indexes', ds.indexes)

Environment:

Output of <tt>xr.show_versions()</tt>

INSTALLED VERSIONS

commit: None python: 3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 5.4.0-47-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.4

xarray: 0.16.0 pandas: 1.1.1 numpy: 1.18.5 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.23.0 distributed: 2.25.0 matplotlib: 3.2.2 cartopy: None seaborn: None numbagg: None pint: 0.13 setuptools: 49.6.0.post20200814 pip: 20.2.3 conda: 4.8.4 pytest: 5.4.3 IPython: 7.15.0 sphinx: 3.2.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dcheriancommented, Sep 11, 2020

I think I was trying to fix this in #4108

0reactions
johnomotanicommented, Sep 13, 2022

Thanks @benbovy - with explicit methods now to produce the result with or without index, I think we can close this now 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xarray for raster data (DEMs) with inconsistent spatial extent
I've been spinning up a new project and have been trying to use xarray, ... I should be able to have x and...
Read more >
Dimension (NetCDF-Java CDM API v5.1.0)
When a Dimension is shared, it has a unique name within its Group. It may have a coordinate Variable, which gives each index...
Read more >
Class CoordinateArrays | NetTopologySuite
Utility method ensuring array contents are of the specified dimension and measures. Array is returned unmodified if consistent, or a copy of the...
Read more >
Indexing and selecting data — xarray 0.10.3 documentation
If any indexer DataArray has coordinates and no coordinate with the same name exists, attach them to the indexed object. Note. Only 1-dimensional...
Read more >
Geo-spatial Indexes | Manual | ArangoDB Documentation
If you use a geo index and upgrade from a version below 3.10 to a version of 3.10 or higher, it is recommended...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found