ERR: better error message on invalid window when using .rolling · Issue #12669 · pandas-dev/pandas (original) (raw)
xref #12765. Let's pick up this as a test case and give a more meaningful error message. e.g. for Window
the win_type
is missing, so this should be the error.
In [15]: pd.DataFrame(np.arange(10)).rolling(2., center=True).median()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-73c4e557093d> in <module>()
----> 1 pd.DataFrame(np.arange(10)).rolling(2., center=True).median()
/usr/lib/python3.5/site-packages/pandas/core/window.py in median(self, **kwargs)
811 @Appender(_shared_docs['median'])
812 def median(self, **kwargs):
--> 813 return super(Rolling, self).median(**kwargs)
814
815 @Substitution(name='rolling')
/usr/lib/python3.5/site-packages/pandas/core/window.py in median(self, how, **kwargs)
592 if self.freq is not None and how is None:
593 how = 'median'
--> 594 return self._apply('roll_median_c', how=how, **kwargs)
595
596 _shared_docs['std'] = dedent("""
/usr/lib/python3.5/site-packages/pandas/core/window.py in _apply(self, func, window, center, check_minp, how, **kwargs)
473 # calculation function
474 if center:
--> 475 offset = _offset(window, center)
476 additional_nans = np.array([np.NaN] * offset)
477
/usr/lib/python3.5/site-packages/pandas/core/window.py in _offset(window, center)
1356 def _offset(window, center):
1357 if not com.is_integer(window):
-> 1358 window = len(window)
1359 offset = (window - 1) / 2. if center else 0
1360 try:
TypeError: object of type 'float' has no len()
Note that pd.DataFrame(np.arange(10)).rolling(2.).median()
works fine.
pandas 0.18.0.