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 499988033,MDU6SXNzdWU0OTk5ODgwMzM=,3356,Explain name matching rules for dimension and non-dimension coordinates,2818208,open,0,,,2,2019-09-29T23:29:19Z,2020-11-29T01:36:57Z,,CONTRIBUTOR,,,,"This arose as part of https://github.com/pydata/xarray/pull/3352. Xarray has important-to-understand name-matching rules for whether or not a coordinate array is a dimension coordinate or a non-dimension coordinate. To my knowledge, this is not in the documentation anywhere. This is what I had, but we decided to remove it since it was overly complicated for a list of key terms; maybe it'll be helpful going forward: > **Name matching rules:** Xarray follows simple but important-to-understand name matching rules for dimensions and coordinates. Let ``arr`` be an array with an existing dimension ``x`` and assigned new coordinates ``new_coords``. If ``new_coords`` is a list-like for e.g. ``[1, 2, 3]`` then they must be assigned a name that matches an existing dimension. For example, if ``arr.assign_coords({'x': [1, 2, 3]}).`` > > However, if ``new_coords`` is a one-dimensional ``DataArray``, then the rules are slightly more complex. In this case, if both ``new_coords``'s name and only dimension match any dimension name in ``arr.dims``, it is assigned as a dimension coordinate to ``arr``. If ``new_coords``'s name matches a name in ``arr.dims`` but its own dimension name does not, it is assigned as a non-dimension coordinate with name ``new_coords.dims[0]`` to ``arr``. Otherwise, an exception is raised.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3356/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue 495920497,MDU6SXNzdWU0OTU5MjA0OTc=,3324,`sel` fails confusingly or silently when a dimension name matches an optional argument,2818208,open,0,,,10,2019-09-19T17:02:17Z,2019-09-20T21:23:18Z,,CONTRIBUTOR,,,,"Given that many Xarray methods accept `dict` or keyword arguments, this may effect other methods. That said, here is a minimal example with `sel`. #### Minimal example If I want to select based on a dimension named `method`, I cannot because Xarray thinks `method` is the `method` argument to `sel`: ```python >>> da1 = xr.DataArray(range(3), dims=['method'], coords={'method': range(3)}) >>> da1 array([0, 1, 2]) Coordinates: * method (method) int64 0 1 2 >>> da1.sel(method=0) ... TypeError: ``method`` must be a string ``` And if the `method` dimension has string labels, this fails silently: ```python >>> da2 = xr.DataArray(range(3), dims=['method'], coords={'method': list('abc')}) >>> da2.sel(method='a') array([0, 1, 2]) Coordinates: * method (method)