-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency in whether index is created with new dimension coordinate? #4417
Comments
Workaround for possible bug with xarray, pydata/xarray#4417, needed for ensuring consistency so we can test for 'identical'.
Thanks for the clear example @johnomotani ! IIRC, the second creates an index because I can see why this is a bit confusing, though it's not an unreasonable default imo. There have been some discussions on this on the issue tracker. Does |
I haven't managed to get
Produces a Dataset that now has an index One suggested solution in #2461 was to use
But (1) having to use I found the behaviour confusing because I wasn't aware of the index variables at all... I create a coordinate with I may well be missing other context that makes this an undesirable thing to do, but for my use-case at least, I think it would make more sense if |
I think I was trying to fix this in #4108 |
From discussions in #4825 and elsewhere (e.g., #6607 (comment)), could we say that we're going towards a consensus that the index vs. coordinate API should be decoupled wherever possible? If that's the case, then Apparently @johnomotani from your example it looks like the two alternatives below would produce the desired result with v2022.6.0:
I would encourage using the latter. It is more verbose but clearer (each method is explicit). Note also that Xarray now also supports non-dimension coordinates with an index. Once #6971 is merged, renaming "b" to "x" won't be needed. Instead you'll be able to do something like:
|
Thanks @benbovy - with explicit methods now to produce the result with or without index, I think we can close this now 😃 |
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 emptyindexes
, second one hasx
inindexes
), even though both Datasets have a 'dimension coordinate'x
:(1)
(2)
Environment:
Output of xr.show_versions()
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
The text was updated successfully, but these errors were encountered: