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/1537#issuecomment-326157538,https://api.github.com/repos/pydata/xarray/issues/1537,326157538,MDEyOklzc3VlQ29tbWVudDMyNjE1NzUzOA==,1217238,2017-08-31T00:44:41Z,2017-08-31T00:44:41Z,MEMBER,"OK, here we go: ``` In [25]: class GoodWrappedArray(object): ...: def __init__(self, array): ...: self.array = array ...: def __array__(self, dtype=None): ...: return np.asarray(self.array, dtype) ...: def __getitem__(self, key): ...: return self.array[key] ...: def __len__(self): ...: return len(self.array) ...: In [26]: ind = GoodWrappedArray(np.array([True, False, True])) In [27]: np.arange(3)[ind] Out[27]: array([0, 2]) In [28]: class BadWrappedArray(object): ...: def __init__(self, array): ...: self.array = array ...: def __array__(self, dtype=None): ...: return np.asarray(self.array, dtype) ...: def __getitem__(self, key): ...: return BadWrappedArray(self.array[key]) ...: def __len__(self): ...: return len(self.array) ...: In [29]: ind = BadWrappedArray(np.array([True, False, True])) In [30]: np.arange(3)[ind] Out[32]: array([], shape=(0, 3), dtype=int64) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,253975242 https://github.com/pydata/xarray/issues/1537#issuecomment-326157080,https://api.github.com/repos/pydata/xarray/issues/1537,326157080,MDEyOklzc3VlQ29tbWVudDMyNjE1NzA4MA==,1217238,2017-08-31T00:41:25Z,2017-08-31T00:41:25Z,MEMBER,"Two more clues: LazilyIndexedArray suffices to duplicate this issue: ``` In [20]: ind = xr.core.indexing.LazilyIndexedArray(np.array([True, False, True])) In [21]: np.arange(3)[ind] Out[21]: array([], shape=(0, 3), dtype=int64) ``` But this simple array wrapper does not: ``` In [17]: class WrappedArray(object): ...: def __init__(self, array): ...: self.array = array ...: def __array__(self, dtype=None): ...: return np.asarray(self.array, dtype) ...: def __getitem__(self, key): ...: return WrappedArray(self.array[key]) ...: @property ...: def shape(self): ...: return self.array.shape ...: @property ...: def dtype(self): ...: return self.array.dtype ...: In [18]: ind = WrappedArray(np.array([True, False, True])) In [19]: np.arange(3)[ind] Out[19]: array([0, 2]) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,253975242 https://github.com/pydata/xarray/issues/1537#issuecomment-326037970,https://api.github.com/repos/pydata/xarray/issues/1537,326037970,MDEyOklzc3VlQ29tbWVudDMyNjAzNzk3MA==,1217238,2017-08-30T16:01:32Z,2017-08-30T16:01:32Z,MEMBER,"I think this is probably an upstream (numpy) bug. Indexing a NumPy array by an array-like object should be equivalent to casting it to a numpy array, i.e., `array[np.asarray(ind)]`.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,253975242