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/7021#issuecomment-1452521051,https://api.github.com/repos/pydata/xarray/issues/7021,1452521051,IC_kwDOAMm_X85Wk7Zb,39671216,2023-03-02T20:47:11Z,2023-03-02T20:47:11Z,CONTRIBUTOR,"Been half a year and I found myself stuck at this inconsistent behavior again.  Another problem I found but haven't mentioned yet is that `DatasetRolling.construct` will swap the rolling dimension name with `window_dim` when `DataArrayRolling.construct` doesn't.

This time, I've actually identified a cause for this problem below:

https://github.com/pydata/xarray/blob/b018442c8dfa3e71ec35e294de69e2011949afec/xarray/core/rolling.py#L789-L791

```python
.isel({d: slice(None, None, s) for d, s in zip(self.dim, strides)}) 
```

I currently still can't figure it out what is the original intention that `.isel` trying to achieve since it causes so much problem without any benefit. It should be noted that this can explode the memory if `xr.Dataset` is reasonably large (It just explode 3 channels PPG, 135Hz, 6Hrs of recording, a mere 300MB to 20-40GB++, so I think this is critical).

## Solution
Removing `.isel` part fixed everything.
### Test case
```python
test_arr = xr.DataArray(np.arange(8).reshape(2, 4), dims=('a', 'b'))  # Borrowed from `DataArray.__doc__`'s example.
test_dset= xr.Dataset(data_vars={i: tr for i in range(3)})
```
DataArray
```python
tr.rolling(b=2).construct('window_dim', stride=2)

>>> <xarray.DataArray (a: 2, b: 2, window_dim: 2)>
array([[[nan,  0.],
        [ 1.,  2.]],

       [[nan,  4.],
        [ 5.,  6.]]])
Dimensions without coordinates: a, b, window_dim
```
Dataset
```python
trd.rolling(b=2).construct('window_dim', stride=2)

>>> <xarray.Dataset>
Dimensions:  (a: 2, b: 2, window_dim: 2)
Dimensions without coordinates: a, b, window_dim
Data variables:
    0        (a, b, window_dim) float64 nan 0.0 1.0 2.0 nan 4.0 5.0 6.0
    1        (a, b, window_dim) float64 nan 0.0 1.0 2.0 nan 4.0 5.0 6.0
    2        (a, b, window_dim) float64 nan 0.0 1.0 2.0 nan 4.0 5.0 6.0

trd.rolling(b=2).construct('window_dim', stride=2)[0]

>>> <xarray.DataArray 0 (a: 2, b: 2, window_dim: 2)>
array([[[nan,  0.],
        [ 1.,  2.]],

       [[nan,  4.],
        [ 5.,  6.]]])
Dimensions without coordinates: a, b, window_dim
```
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1370063272
https://github.com/pydata/xarray/issues/7021#issuecomment-1244634332,https://api.github.com/repos/pydata/xarray/issues/7021,1244634332,IC_kwDOAMm_X85KL5zc,39671216,2022-09-12T22:39:35Z,2022-09-12T22:42:11Z,CONTRIBUTOR,"> Thanks for the report & I agree that this should lead to the same but the code paths are indeed different - but I have not looked in to the actual root cause. Could be that this is also not super thoroughly tested (and used!):
> 
> https://github.com/pydata/xarray/blob/b018442c8dfa3e71ec35e294de69e2011949afec/xarray/core/rolling.py#L289
> 
> https://github.com/pydata/xarray/blob/b018442c8dfa3e71ec35e294de69e2011949afec/xarray/core/rolling.py#L721
> 
> B.t.w. a copy-pastable example would be appreciated.

Thanks for the response, here is a straightforward example.

```python
import xarray as xr
dummy = list(range(100))
x, y, z = [xr.DataArray(dummy, dims=['t']) for _ in range(3)]
ds = xr.Dataset(
    {'x': x, 'y': y, 'z': z}
)
print(x.rolling(t=4).construct('w', stride=4).shape)
print(ds.rolling(t=4).construct('w', stride=4).x.shape)
```
**Results:**
```
> (25, 4)
> (7, 4)
```

I had a hunch that the problem come from this part - not quite sure what self._mapping_to_list did here, haven't look it up yet.
https://github.com/pydata/xarray/blob/b018442c8dfa3e71ec35e294de69e2011949afec/xarray/core/rolling.py#L764-L772

Since I only had one dimension to deal with, removing this loop solves the problem for me.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1370063272