home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 199816142

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
199816142 MDU6SXNzdWUxOTk4MTYxNDI= 1197 Problem with creating coords by dict 25030860 closed 0     7 2017-01-10T13:05:25Z 2017-08-31T19:17:29Z 2017-08-31T19:17:29Z NONE      

IMO there's a problem with using dicts as coords definition for DataArrays. E.g. an array defined by import xarray as xr arr = xr.DataArray(np.zeros([1, 2, 3]), {'x': [1], 'y': [1, 2], 'z': [1, 2, 3]}) will lead to an exception when tried to be indexed like arr[0, 0, 0]

The error message is ValueError: conflicting sizes for dimension 'z': length 2 on <this-array> and length 3 on 'z'

As far as I can imagine this is because dicts don't preserve order in python. At least printing the coords shows a different order than used in the definition of arr: arr.coords Coordinates: * x (x) int32 1 * z (z) int32 1 2 3 * y (y) int32 1 2

Using an ordered dict turns out to work: import collections od = collections.OrderedDict([('x', [1]), ('y', [1, 2]), ('z', [1, 2, 3])]) arr = xr.DataArray(np.zeros([1, 2, 3]), od) And so does using a list of tuples: arr = xr.DataArray(np.zeros([1, 2, 3]), [('x', [1]), ('y', [1, 2]), ('z', [1, 2, 3])])

Both lead to arr[0, 0, 0] <xarray.DataArray ()> array(0.0) Coordinates: x int32 1 y int32 1 z int32 1 as expected.

Detected in WinPython-64bit-3.4.4.1Qt5 with xarray version 0.7.0

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

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 7 rows from issue in issue_comments
Powered by Datasette · Queries took 0.627ms · About: xarray-datasette