home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 604430213

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/3287#issuecomment-604430213 https://api.github.com/repos/pydata/xarray/issues/3287 604430213 MDEyOklzc3VlQ29tbWVudDYwNDQzMDIxMw== 6200806 2020-03-26T13:26:59Z 2020-03-26T13:26:59Z CONTRIBUTOR

Thanks @max-sixty. Contrary to my warning about not doing a PR, I couldn't help myself and dug in a bit. It turns out that string coordinates aren't the problem, it's when the coordinate isn't in sorted order. For example, @chrisroat's original example doesn't error if the coordinate is ["G", "R"] instead of ["R", "G"]. A more concrete WIP test:

```python def test_stack_groupby_unsorted_coord(): data = [[0, 1], [2, 3]] data_flat = [0, 1, 2, 3] dims = ["y", "x"] y_vals = [2, 3]

# "y" coord is in sorted order, and everything works
arr = xr.DataArray(data, dims=dims, coords={"y": y_vals})
actual1 = arr.stack(z=["y", "x"]).groupby("z").first()
midx = pd.MultiIndex.from_product([[2, 3], [0, 1]], names=dims)
expected1 = xr.DataArray(data_flat, dims=["z"], coords={"z": midx})
xr.testing.assert_equal(actual1, expected1)

# Now "y" coord is NOT in sorted order, and the bug appears
arr = xr.DataArray(data, dims=dims, coords={"y": y_vals[::-1]})
actual2 = arr.stack(z=["y", "x"]).groupby("z").first()
midx = pd.MultiIndex.from_product([[3, 2], [0, 1]], names=dims)
expected2 = xr.DataArray(data_flat, dims=["z"], coords={"z": midx})
xr.testing.assert_equal(actual2, expected2)

test_stack_groupby_str_coords() yieldspython


AssertionError Traceback (most recent call last)

[...]

AssertionError: Left and right DataArray objects are not equal

Differing values: L array([2, 3, 0, 1]) R array([0, 1, 2, 3]) Differing coordinates: L * z (z) MultiIndex - z_leve...(z) int64 2 2 3 3 - z_leve...(z) int64 0 1 0 1 R * z (z) MultiIndex - y (z) int64 3 3 2 2 - x (z) int64 0 1 0 1 ```

I'll return to this tomorrow, in the meantime if this triggers any thoughts about the best path forward, that would be much appreciated!

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