Repository: pandas-dev/pandas

Issue:
ERR: consistency in rolling on empty frames
xref https://github.com/pandas-dev/pandas/pull/15795/files#r108178445

I think we should just return an empty frame for [4]
```
In [4]: DataFrame().rolling('1s').sum()
ValueError: window must be an integer

In [5]: DataFrame().rolling(1).sum()
Out[5]: 
Empty DataFrame
Columns: []
Index: []
```

though this works.

```
In [7]: DataFrame(index=pd.DatetimeIndex([])).rolling(1).sum()
Out[7]: 
Empty DataFrame
Columns: []
Index: []

In [8]: DataFrame(index=pd.DatetimeIndex([])).rolling('1s').sum()
Out[8]: 
Empty DataFrame
Columns: []
Index: []
```


Discussion:
cc @chrisaycock 
cc @carlosdanielcsantos
I agree they should be consistent.
Working on this at PyCon sprint

Resolving patch:
diff --git a/pandas/core/window.py b/pandas/core/window.py
--- a/pandas/core/window.py
+++ b/pandas/core/window.py
@@ -1074,7 +1074,7 @@ def validate(self):
         super(Rolling, self).validate()
 
         # we allow rolling on a datetimelike index
-        if (self.is_datetimelike and
+        if ((self.obj.empty or self.is_datetimelike) and
                 isinstance(self.window, (compat.string_types, DateOffset,
                                          timedelta))):
 


Test patch:
diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py
--- a/pandas/tests/test_window.py
+++ b/pandas/tests/test_window.py
@@ -441,6 +441,20 @@ def test_closed(self):
         with pytest.raises(ValueError):
             df.rolling(window=3, closed='neither')
 
+    @pytest.mark.parametrize('roller', ['1s', 1])
+    def tests_empty_df_rolling(self, roller):
+        # GH 15819 Verifies that datetime and integer rolling windows can be
+        # applied to empty DataFrames
+        expected = DataFrame()
+        result = DataFrame().rolling(roller).sum()
+        tm.assert_frame_equal(result, expected)
+
+        # Verifies that datetime and integer rolling windows can be applied to
+        # empty DataFrames with datetime index
+        expected = DataFrame(index=pd.DatetimeIndex([]))
+        result = DataFrame(index=pd.DatetimeIndex([])).rolling(roller).sum()
+        tm.assert_frame_equal(result, expected)
+
 
 class TestExpanding(Base):
 
@@ -483,6 +497,24 @@ def test_numpy_compat(self):
             tm.assert_raises_regex(UnsupportedFunctionCall, msg,
                                    getattr(e, func), dtype=np.float64)
 
+    @pytest.mark.parametrize(
+        'expander',
+        [1, pytest.mark.xfail(
+            reason='GH 16425 expanding with offset not supported')('1s')])
+    def tests_empty_df_expanding(self, expander):
+        # GH 15819 Verifies that datetime and integer expanding windows can be
+        # applied to empty DataFrames
+        expected = DataFrame()
+        result = DataFrame().expanding(expander).sum()
+        tm.assert_frame_equal(result, expected)
+
+        # Verifies that datetime and integer expanding windows can be applied
+        # to empty DataFrames with datetime index
+        expected = DataFrame(index=pd.DatetimeIndex([]))
+        result = DataFrame(
+            index=pd.DatetimeIndex([])).expanding(expander).sum()
+        tm.assert_frame_equal(result, expected)
+
 
 class TestEWM(Base):