<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np

s = pd.Series([1, 2, 3, np.nan, 5], index=pd.date_range('2017-01-01', '2017-01-05'))
print(s.rolling('3d', min_periods=1).apply(lambda x: 42))
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-s1">np</span>.<span class="pl-s1">nan</span>, <span class="pl-c1">5</span>], <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2017-01-01'</span>, <span class="pl-s">'2017-01-05'</span>))
<span class="pl-en">print</span>(<span class="pl-s1">s</span>.<span class="pl-en">rolling</span>(<span class="pl-s">'3d'</span>, <span class="pl-s1">min_periods</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-c1">42</span>))</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Output of the above code sample:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2017-01-01    42.0
2017-01-02    42.0
2017-01-03    42.0
2017-01-04     NaN
2017-01-05    42.0"><pre class="notranslate"><code class="notranslate">2017-01-01    42.0
2017-01-02    42.0
2017-01-03    42.0
2017-01-04     NaN
2017-01-05    42.0
</code></pre></div>
<p dir="auto">It seems that the user function did not get applied to the window corresponding to the original NaN row, resulting in NaN as the result for that row. Why is that? The more reasonable output would be all 42 because by the <code class="notranslate">min_periods</code> constraint, all of the windows are valid.</p>
<p dir="auto">Compare this to the equivalent fixed window version:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="s = pd.Series([1, 2, 3, np.nan, 5])
print(s.rolling(3, min_periods=1).apply(lambda x: 42))"><pre class="notranslate"><span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-s1">np</span>.<span class="pl-s1">nan</span>, <span class="pl-c1">5</span>])
<span class="pl-en">print</span>(<span class="pl-s1">s</span>.<span class="pl-en">rolling</span>(<span class="pl-c1">3</span>, <span class="pl-s1">min_periods</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-c1">42</span>))</pre></div>
<p dir="auto">which gives the following output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="0    42.0
1    42.0
2    42.0
3    42.0
4    42.0"><pre class="notranslate"><code class="notranslate">0    42.0
1    42.0
2    42.0
3    42.0
4    42.0
</code></pre></div>
<p dir="auto">Is this inconsistency between fixed and variable size window a desired behavior?</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2017-01-01    42.0
2017-01-02    42.0
2017-01-03    42.0
2017-01-04    42.0
2017-01-05    42.0"><pre class="notranslate"><code class="notranslate">2017-01-01    42.0
2017-01-02    42.0
2017-01-03    42.0
2017-01-04    42.0
2017-01-05    42.0
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 2.7.13.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.11.9-1-ARCH<br>
machine: x86_64<br>
processor:<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.21.0.dev+316.gf2b0bdc9b<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 36.2.5<br>
Cython: 0.26<br>
numpy: 1.13.1<br>
scipy: None<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.4.1<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd

df = pd.DataFrame({'A': [0, 1, 2, 3, 4]},
                  index=[pd.Timestamp('20130101 09:00:00'),
                         pd.Timestamp('20130101 09:00:01'),
                         pd.Timestamp('20130101 09:00:02'),
                         pd.Timestamp('20130101 09:00:03'),
                         pd.Timestamp('20130101 09:00:04')])
rolled = df.rolling('3s', 3)

print rolled.sum()
print rolled.apply(sum)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'A'</span>: [<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>]},
                  <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'20130101 09:00:00'</span>),
                         <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'20130101 09:00:01'</span>),
                         <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'20130101 09:00:02'</span>),
                         <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'20130101 09:00:03'</span>),
                         <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'20130101 09:00:04'</span>)])
<span class="pl-s1">rolled</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">rolling</span>(<span class="pl-s">'3s'</span>, <span class="pl-c1">3</span>)

<span class="pl-k">print</span> <span class="pl-s1">rolled</span>.<span class="pl-en">sum</span>()
<span class="pl-k">print</span> <span class="pl-s1">rolled</span>.<span class="pl-en">apply</span>(<span class="pl-s1">sum</span>)</pre></div>
<p dir="auto">outputs</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="                       A
2013-01-01 09:00:00  NaN
2013-01-01 09:00:01  NaN
2013-01-01 09:00:02  3.0
2013-01-01 09:00:03  6.0
2013-01-01 09:00:04  9.0

                      A
2013-01-01 09:00:00 NaN
2013-01-01 09:00:01 NaN
2013-01-01 09:00:02 NaN
2013-01-01 09:00:03 NaN
2013-01-01 09:00:04 NaN"><pre class="notranslate"><code class="notranslate">                       A
2013-01-01 09:00:00  NaN
2013-01-01 09:00:01  NaN
2013-01-01 09:00:02  3.0
2013-01-01 09:00:03  6.0
2013-01-01 09:00:04  9.0

                      A
2013-01-01 09:00:00 NaN
2013-01-01 09:00:01 NaN
2013-01-01 09:00:02 NaN
2013-01-01 09:00:03 NaN
2013-01-01 09:00:04 NaN
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">rolled.apply.sum() should give the same output as rolled.apply(sum) but instead only returns nan.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">same as rolled.sum()</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-59-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
<p dir="auto">pandas: 0.19.2<br>
nose: None<br>
pip: 9.0.1<br>
setuptools: 20.7.0<br>
Cython: None<br>
numpy: 1.12.0<br>
scipy: 0.18.1<br>
statsmodels: 0.6.1<br>
xarray: None<br>
IPython: 5.1.0<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
matplotlib: 1.5.3<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
boto: 2.38.0<br>
pandas_datareader: None</p>
</details>