home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 527684331

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/3238#issuecomment-527684331 https://api.github.com/repos/pydata/xarray/issues/3238 527684331 MDEyOklzc3VlQ29tbWVudDUyNzY4NDMzMQ== 14808389 2019-09-03T23:57:11Z 2019-09-04T15:35:58Z MEMBER

After digging a little bit more, I think the reason why filterwarnings() made me think the indexing tests pass is that when a UnitStrippedWarning is raised (mostly after accessing __array_struct__), the filter replaces it with a DimensionalityError, complaining that it can't convert to dimensionless. This confuses me: when directly accessing an attribute starting with __array_, pytest correctly points out the raised UnitStrippedWarning.

Also, it seems that because DimensionalityError inherits from ValueError, the type of the parameter index of convert_label_indexer is changed from Int64Index to Index (which has dtype="object" ), which does not cast to ndarray, thus keeping the unit information and causing sel() to correctly raise a KeyError. I can reproduce both behaviors using ```python import numpy as np import pytest import xarray as xr

pint = pytest.importorskip("pint") ureg = pint.UnitRegistry()

@pytest.mark.xfail def test_indexing_fail(): array = np.linspace(1, 2, 20) * ureg.m x = np.arange(len(array)) * ureg.s data_array = xr.DataArray(data=array, coords={"x": x}, dims=["x"]) with pytest.raises(KeyError): data_array.sel(x=np.array([13, 5, 9]) * ureg.m)

@pytest.mark.filterwarnings("error:::pint[.*]") def test_indexing_pass(): array = np.linspace(1, 2, 20) * ureg.m x = np.arange(len(array)) * ureg.s data_array = xr.DataArray(data=array, coords={"x": x}, dims=["x"]) with pytest.raises(KeyError): data_array.sel(x=np.array([13, 5, 9]) * ureg.m) ``` Note: the only difference between the two is the decorator.

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