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/2450#issuecomment-426398519,https://api.github.com/repos/pydata/xarray/issues/2450,426398519,MDEyOklzc3VlQ29tbWVudDQyNjM5ODUxOQ==,6628425,2018-10-02T19:21:45Z,2018-10-02T19:21:45Z,MEMBER,"This seems like an xarray version issue; the `other` argument was not added to `where` until [version 0.10.0](http://xarray.pydata.org/en/stable/whats-new.html#id117). Are you running this script on a different platform than before? I'm surprised your original code,
https://github.com/pydata/xarray/issues/2450#issuecomment-426346137, didn't raise the same error.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426392397,https://api.github.com/repos/pydata/xarray/issues/2450,426392397,MDEyOklzc3VlQ29tbWVudDQyNjM5MjM5Nw==,6628425,2018-10-02T19:01:16Z,2018-10-02T19:01:16Z,MEMBER,"> Gonna try with just the first of the four
👍 let me know how it goes.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426381265,https://api.github.com/repos/pydata/xarray/issues/2450,426381265,MDEyOklzc3VlQ29tbWVudDQyNjM4MTI2NQ==,6628425,2018-10-02T18:27:17Z,2018-10-02T18:27:17Z,MEMBER,Does `complete_shear` happen to return more than one DataArray?,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426374411,https://api.github.com/repos/pydata/xarray/issues/2450,426374411,MDEyOklzc3VlQ29tbWVudDQyNjM3NDQxMQ==,6628425,2018-10-02T18:07:16Z,2018-10-02T18:07:16Z,MEMBER,"@am-thyst could you show all the code that you used to try it out? If I run all the lines (from 1-8 in
https://github.com/pydata/xarray/issues/2450#issuecomment-426340226 and https://github.com/pydata/xarray/issues/2450#issuecomment-426353764) in my IPython console things work for me.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426353764,https://api.github.com/repos/pydata/xarray/issues/2450,426353764,MDEyOklzc3VlQ29tbWVudDQyNjM1Mzc2NA==,6628425,2018-10-02T17:07:37Z,2018-10-02T17:07:37Z,MEMBER,"@am-thyst thanks for the extra details -- try out my method -- I think it does the same thing. Well perhaps you'll just need to multiply the result by 100 at the end and use `>=` instead of `>` for the threshold condition :)
Your approach can also be vectorized in such a way that you don't need to manually iterate over the individual times:
```
In [6]: b = da.where(da >= threshold, other=0)
In [7]: c = b.where(b == 0, other=1)
In [8]: (c.sum('time') / c.sizes['time']) * 100
Out[8]:
array([[ 25., 50., 25.],
[ 25., 50., 50.]])
Dimensions without coordinates: x, y
```
Effectively `da >= threshold` in my earlier example is shorthand for lines 6 and 7 from the example above (and taking the mean is the same as summing over the dimension and dividing by the number of elements along that dimension).","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426340226,https://api.github.com/repos/pydata/xarray/issues/2450,426340226,MDEyOklzc3VlQ29tbWVudDQyNjM0MDIyNg==,6628425,2018-10-02T16:28:42Z,2018-10-02T16:28:42Z,MEMBER,"I'm not sure if I'm understanding the calculation correctly; is something like the following what you are looking for?
```
In [1]: import numpy as np; import pandas as pd; import xarray as xr
In [2]: times = pd.date_range('1979', periods=4, freq='12H')
In [3]: da = xr.DataArray(np.random.rand(4, 2, 3), coords={'time': times}, dims=['time', 'x', 'y'])
In [4]: threshold = 0.5
In [5]: (da > threshold).mean('time')
Out[5]:
array([[ 0.25, 0.5 , 0.25],
[ 0.25, 0.5 , 0.5 ]])
Dimensions without coordinates: x, y
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426317958,https://api.github.com/repos/pydata/xarray/issues/2450,426317958,MDEyOklzc3VlQ29tbWVudDQyNjMxNzk1OA==,6628425,2018-10-02T15:27:59Z,2018-10-02T15:36:28Z,MEMBER,@am-thyst could you provide more details on what sort of operation you are trying to do with each time slice? Typically this kind of process can be better handled in a vectorized way (i.e. without manually iterating over the times).,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396
https://github.com/pydata/xarray/issues/2450#issuecomment-426250976,https://api.github.com/repos/pydata/xarray/issues/2450,426250976,MDEyOklzc3VlQ29tbWVudDQyNjI1MDk3Ng==,6628425,2018-10-02T12:16:03Z,2018-10-02T12:16:03Z,MEMBER,"Thanks @am-thyst, this happens to be expected behavior. For a dimension indexed by a DatetimeIndex (e.g. your `'time'` dimension), label-based indexing with strings uses so-called [""partial string indexing""](https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing). This behavior in xarray is inherited from pandas. Essentially what it means is that if you provide a string to a label-based indexer (like `.loc`), then it will return values from all times that would begin with the string you provided if expressed in string form. So, in your example, if you provide only the year, month, and day (e.g. `'1979-01-01'`) it will return values from `'1979-01-01'` and `1979-01-01T12:00:00`, because both string representations start with `'1979-01-01'`.
As you inferred, if you add detail to the string you provide, you can refine the selection. That said, you need to be careful of the format you use (I think the reason you get a `KeyError` in your second example is that pandas does not know how to interpret the string you provided). While pandas has some flexibility in how it parses datetime-strings I might recommend sticking to the [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601), which should work in all cases. For example to select just the values associated with the first date in your array you could do something like this:
```
In [1]: import numpy as np; import pandas as pd; import xarray as xr
In [2]: times = pd.date_range('1979', periods=8, freq='12H')
In [3]: da = xr.DataArray(np.arange(8), coords=[times], dims=['time'])
In [4]: da
Out[4]:
array([0, 1, 2, 3, 4, 5, 6, 7])
Coordinates:
* time (time) datetime64[ns] 1979-01-01 ... 1979-01-04T12:00:00
In [5]: da.loc['1979-01-01T00']
Out[5]:
array(0)
Coordinates:
time datetime64[ns] 1979-01-01
```
One other thing to note, in general, is that you can pass datetimes themselves to label-based indexers if you want to select specific dates; this way you don't need to go through the intermediate step of converting a date to a string:
```
In [6]: da.loc[datetime(1979, 1, 1)]
Out[6]:
array(0)
Coordinates:
time datetime64[ns] 1979-01-01
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,365438396