question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERR: Most consistent error handling when passing win_type='freq' in rolling

See original GitHub issue

Working on https://github.com/dask/dask/issues/2190 (df.rolling(‘5s’) for dask), and I think these should all be equivalent.

In [26]: import pandas as pd
In [27]: import numpy as np
In [31]: from pandas.tseries.frequencies import to_offset
In [28]: s = pd.Series(range(10), index=pd.date_range('2017', freq='s', periods=10))
>>> s.rolling('2s')  # Case 1: correct
>>> s.rolling(window=2000000000, min_periods=1, win_type='freq')  # Case 2
>>> s.rolling(window=to_offset('2s'), min_periods=1, win_type='freq')  # Case 3
>>> s.rolling(window=pd.Timedelta('2s'), min_periods=1, win_type='freq')  # Same as 3

I don’t think there are any parsing ambiguities.

Currently we have

# Case 1
In [33]: s.rolling('2s')
Out[33]: Rolling [window=2000000000,min_periods=1,center=False,win_type=freq,axis=0]
# Case 2
In [35]: s.rolling(window=2000000000, min_periods=1, win_type='freq')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-a24a29dff0ab> in <module>()
----> 1 s.rolling(window=2000000000, min_periods=1, win_type='freq')

/Users/taugspurger/.virtualenvs/dask-dev/lib/python3.6/site-packages/pandas/core/generic.py in rolling(self, window, min_periods, freq, center, win_type, on, axis)
   5502                                    min_periods=min_periods, freq=freq,
   5503                                    center=center, win_type=win_type,
-> 5504                                    on=on, axis=axis)
   5505
   5506         cls.rolling = rolling

/Users/taugspurger/.virtualenvs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in rolling(obj, win_type, **kwds)
   1795
   1796     if win_type is not None:
-> 1797         return Window(obj, win_type=win_type, **kwds)
   1798
   1799     return Rolling(obj, **kwds)

/Users/taugspurger/.virtualenvs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in __init__(self, obj, window, min_periods, freq, center, win_type, axis, on, **kwargs)
     76         self.win_type = win_type
     77         self.axis = obj._get_axis_number(axis) if axis is not None else None
---> 78         self.validate()
     79
     80     @property

/Users/taugspurger/.virtualenvs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in validate(self)
    505                 raise ValueError('Invalid win_type {0}'.format(self.win_type))
    506             if getattr(sig, self.win_type, None) is None:
--> 507                 raise ValueError('Invalid win_type {0}'.format(self.win_type))
    508         else:
    509             raise ValueError('Invalid window {0}'.format(window))

ValueError: Invalid win_type freq
# Case 3
In [36]: s.rolling(window=to_offset('2s'), min_periods=1, win_type='freq')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-93e14a8d05f6> in <module>()
----> 1 s.rolling(window=to_offset('2s'), min_periods=1, win_type='freq')

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/core/generic.py in rolling(self, window, min_periods, freq, center, win_type, on, axis)
   5502                                    min_periods=min_periods, freq=freq,
   5503                                    center=center, win_type=win_type,
-> 5504                                    on=on, axis=axis)
   5505
   5506         cls.rolling = rolling

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in rolling(obj, win_type, **kwds)
   1795
   1796     if win_type is not None:
-> 1797         return Window(obj, win_type=win_type, **kwds)
   1798
   1799     return Rolling(obj, **kwds)

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in __init__(self, obj, window, min_periods, freq, center, win_type, axis, on, **kwargs)
     76         self.win_type = win_type
     77         self.axis = obj._get_axis_number(axis) if axis is not None else None
---> 78         self.validate()
     79
     80     @property

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/core/window.py in validate(self)
    507                 raise ValueError('Invalid win_type {0}'.format(self.win_type))
    508         else:
--> 509             raise ValueError('Invalid window {0}'.format(window))
    510
    511     def _prep_window(self, **kwargs):

ValueError: Invalid window <2 * Seconds>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Apr 11, 2017

Can we change the repr of the rolling object to not show win_type=freq ? As I think this is just confusing, win_type='freq' isn’t documented and also shouldn’t work (win_type is for how the values in the window are weighted, so a whole different use case I think)

0reactions
TomAugspurgercommented, Apr 11, 2017

Yeah, I’m fine with that, rather than allowing a user to specify win_type='freq

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling - Apollo GraphQL Docs
When Apollo Server formats an error in a response, it sets the code extension to this value if no other code is set....
Read more >
Error Handling with Angular 8 - Tips and Best Practices
Error handlers provide an opportunity to present friendly information to the user and collect important data for development.
Read more >
Everything you wanted to know about exceptions
When an exception is thrown, that call stack is checked in order for an exception handler to catch it. Terminating and non-terminating errors....
Read more >
10 Handling PL/SQL Errors
Carefully consider whether each exception handler should commit the transaction, roll it back, or let it continue. Remember, no matter how severe the...
Read more >
A mostly complete guide to error handling in JavaScript.
There are many types of errors in JavaScript, namely: ... By doing so you keep error handling consistent through the codebase.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found