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/6953#issuecomment-1230234269,https://api.github.com/repos/pydata/xarray/issues/6953,1230234269,IC_kwDOAMm_X85JU-Kd,28786187,2022-08-29T12:41:47Z,2022-08-29T12:41:47Z,CONTRIBUTOR,"Hi @mathause > It does work if the array keeps the size: > > ```python > data.resample(index=""M"").apply(lambda x: x.values) > ``` Thanks, but I am not sure I find that intuitive, why should the resampled array have the same size as the original? It seems to make only sense for `DataArray.apply()`, but not for a resampled one. As I indicated in my other reply, returning a scalar or equivalent should be fine, shouldn't it? At the very least the documentation is lacking, it refers to the `pandas` method, but clearly the behaviour is different. > As a workaround you could allow your function to consume a dummy axis. Or you could pass `dim` as `...` > > ```python > data.resample(index=""M"").reduce(lambda x, axis: 1) # workaround 1 > data.resample(index=""M"").reduce(lambda x: 1, dim=...) # workaround 2 > ``` > > (`reduce` only passes `axis` if `dim is not None` but `groupby` passes the `group_dim` per default. That feels a bit like curing the symptoms instead of the root cause, why not set `dim='...'` if it is not given?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1350803561 https://github.com/pydata/xarray/issues/6953#issuecomment-1228461073,https://api.github.com/repos/pydata/xarray/issues/6953,1228461073,IC_kwDOAMm_X85JONQR,10194086,2022-08-26T13:03:04Z,2022-08-26T13:03:04Z,MEMBER,"It does work if the array keeps the size: ```python data.resample(index=""M"").apply(lambda x: x.values) ``` As a workaround you could allow your function to consume a dummy axis. Or you could pass `dim` as `...` ```python data.resample(index=""M"").reduce(lambda x, axis: 1) # workaround 1 data.resample(index=""M"").reduce(lambda x: 1, dim=...) # workaround 2 ``` (`reduce` only passes `axis` if `dim is not None` but `groupby` passes the `group_dim` per default. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1350803561 https://github.com/pydata/xarray/issues/6953#issuecomment-1228267515,https://api.github.com/repos/pydata/xarray/issues/6953,1228267515,IC_kwDOAMm_X85JNd_7,28786187,2022-08-26T09:22:21Z,2022-08-26T09:22:21Z,CONTRIBUTOR,"@mathause Thanks, that works for `np.median`, but `.reduce()` passes an `axis=` keyword argument, which needs to be taken care of by any custom function. I used `np.median` here just as an example, as it showed the problem. @dcherian I am not sure if raising an error would be very user friendly. In my opinion, which may be biased by my personal use cases, I would expect `.apply()` (or `.map()` for that matter) of a resample object to take any function that returns a scalar: the value at the resampled point. It should be then up to `xarray` to iterate over any other non-resampled dimensions. I am not sure why it requires to return a DataArray in the first place. As mentioned, it works with pandas series and dataframes, e.g.: ```python data.to_pandas().resample(""M"").apply(np.median) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1350803561 https://github.com/pydata/xarray/issues/6953#issuecomment-1227374907,https://api.github.com/repos/pydata/xarray/issues/6953,1227374907,IC_kwDOAMm_X85JKEE7,2448579,2022-08-25T14:56:35Z,2022-08-25T14:56:35Z,MEMBER,"> `1114 applied_example, applied = peek_at(applied)` We could raise an error here if `applied_example` is not a `DataArray` or `Dataset` but not sure if its worth it. This is a somewhat common user question","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1350803561 https://github.com/pydata/xarray/issues/6953#issuecomment-1227218693,https://api.github.com/repos/pydata/xarray/issues/6953,1227218693,IC_kwDOAMm_X85JJd8F,10194086,2022-08-25T12:53:32Z,2022-08-25T12:53:32Z,MEMBER,"`apply` seems to expect that the applied function returns a DataArray. As an alternative could you use `data.resample(index=""M"").reduce(np.median)`?","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1350803561