home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 46022646

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
46022646 MDU6SXNzdWU0NjAyMjY0Ng== 254 order matters when doing comparisons against scalar xray objects 291576 closed 0   799012 2 2014-10-16T19:03:11Z 2014-10-23T06:43:30Z 2014-10-23T06:43:23Z CONTRIBUTOR      

Working on some bounding box extraction code, I computed a bounding box by taking mins and maxes of the coordinates from an xray object resulting in a dictionary of scalar xray objects. When comparing an xray DataArray against this scalar xray object, the order seems to matter. This results in problems down the road that wouldn't happen if I just had a scalar value instead of a scalar xray object.

```

bbox {'longitude': (<xray.DataArray 'longitude' ()> array(-102.8782), <xray.DataArray 'longitude' ()> array(-94.6244))} a = bbox['longitude'][0] <= mod['longitude'] b = mod['longitude'] <= bbox['longitude'][1] c = mod['longitude'] >= bbox['longitude'][0] a <xray.DataArray 'longitude' (longitude: 7001)> array([False, False, False, ..., True, True, True], dtype=bool) Coordinates: * longitude (longitude) bool False False False False False False False False False ... b <xray.DataArray (longitude: 7001)> array([ True, True, True, ..., False, False, False], dtype=bool) Coordinates: * longitude (longitude) float32 -129.995 -129.985 -129.975 -129.965 -129.955 ... ```

See that the "a" object has a name "longitude" while the "b" object does not. Therefore...

```

a & b Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/nas/home/broot/centos6/lib/python2.7/site-packages/xray/core/dataarray.py", line 850, in func ds = self.coords.merge(other_coords) File "/nas/home/broot/centos6/lib/python2.7/site-packages/xray/core/coordinates.py", line 122, in merge conflicts = self._merge_validate(other) File "/nas/home/broot/centos6/lib/python2.7/site-packages/xray/core/coordinates.py", line 80, in _merge_validate raise ValueError('index %r not aligned' % k) ValueError: index 'longitude' not aligned ```

But, if I use the "c" object instead which was created flipping the comparison around:

```

c * b <xray.DataArray (longitude: 7001)> array([False, False, False, ..., False, False, False], dtype=bool) Coordinates: * longitude (longitude) float32 -129.995 -129.985 -129.975 -129.965 -129.955 ...

```

everything works as expected. I have a vague idea of why this is happening, but I am not exactly sure how one should go about dealing with this. It is a similar problem elsewhere with subclassed numpy arrays. For now, I am going to have to go with the rule of keeping the xray dataarray object first, but that really isn't going to work in other places where I may not know that I am passing xray objects.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/254/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

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