home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 253681755

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/pull/1017#issuecomment-253681755 https://api.github.com/repos/pydata/xarray/issues/1017 253681755 MDEyOklzc3VlQ29tbWVudDI1MzY4MTc1NQ== 4160723 2016-10-14T00:58:46Z 2016-10-14T01:01:07Z MEMBER

Should we create dummy/virtual coordinates like range(n) on demand when indexing a dimension without labels?

I think about some possible use cases where this behavior - if I understand it well - may not be desired. For example, if we want to compute partial derivatives by finite difference, using xarray would not give the expected result (as numpy does):

``` python

z = np.random.rand(5, 5) dz_dx_numpy = z[1:, :] - z[:-1, :] # forward difference dz_dx_numpy array([[-0.16122906, -0.73841927, 0.11565084, 0.94529388, 0.04245993], [ 0.21066572, 0.11964058, -0.11203992, -0.52073269, -0.50827324], [-0.42100012, 0.39873985, 0.07957889, -0.02071456, 0.59944732], [-0.53819024, -0.29738881, 0.35238292, 0.01903809, 0.15671588]])

da = xr.DataArray(z, dims=('x', 'y'), name='z') dz_dx_xarray = da[1:, :] - da[:-1, :] # forward difference dz_dx_xarray <xarray.DataArray 'z' (x: 3, y: 5)> array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]]) Coordinates: * x (x) int64 1 2 3 ```

However, I guess that this specific kind of problem should rather be addressed using the upcoming logic for applying vectorized functions to xarray objects (#964).

e.g., array.coords['x'] would return a DataArray with values range(n) (importantly, this would not change the original array).

That sounds a bit weird to me (I'm not sure to understand, actually). What are the reasons/benefits of returning a DataArray instead of raising a KeyError?

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