home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 495920497

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
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 <xarray.DataArray (method: 3)> 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') <xarray.DataArray (method: 3)> array([0, 1, 2]) Coordinates: * method (method) <U1 'a' 'b' 'c' ```

Expected Output

I think raising a ValueError and providing a clarifying error message is the right call, but maybe the maintainers have a different opinion. At the very least, it seems like Xarray could note that the DataArray instance has a dimension that matches one of the function arguments and ask the user to use dict-like arguments if required.

I imagine a general error handling function could be written to check this for any function and DataArray pair.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3324/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 10 rows from issue in issue_comments
Powered by Datasette · Queries took 0.471ms · About: xarray-datasette