home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 382960446

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2067#issuecomment-382960446 https://api.github.com/repos/pydata/xarray/issues/2067 382960446 MDEyOklzc3VlQ29tbWVudDM4Mjk2MDQ0Ng== 1411280 2018-04-20T03:24:29Z 2018-04-20T03:27:09Z NONE

My issue is not so much with the range but the len. If done during construction from numpy arrays, it might need to be range(data.shape[0]) or range(data.shape[1]) or etc. based on the layout of the data. If done after construction with assign_coords, both the name of the dataset and the name of the dimension need to be written twice. This all creates room for silly mistakes.

On the bright side, the mistakes are quickly caught when the code executes at runtime. On the other side, they can be entirely avoided.


Of course, xarray doesn't have to do this; a user concerned about making these mistakes can easily capture this usage pattern in a wrapper function around assign_coords:

python def assign_auto_coords(da, *dims): """Give each specified dimension of a DataArray or Dataset automatic coords from 0 to n-1.""" return da.assign_coords(**{dim: range(self.sizes[dim]) for dim in dims})

it's merely that first-class support during construction would be nice to have.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  315948443
Powered by Datasette · Queries took 0.428ms · About: xarray-datasette