Skip to content

Confusing - rolling min( ) function "accepting" objects #20244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gojandrooo opened this issue Mar 10, 2018 · 4 comments
Closed

Confusing - rolling min( ) function "accepting" objects #20244

gojandrooo opened this issue Mar 10, 2018 · 4 comments
Labels
Bug Window rolling, ewma, expanding

Comments

@gojandrooo
Copy link
Contributor

gojandrooo commented Mar 10, 2018

Code Sample, a copy-pastable example if possible

s = pd.Series([3,1,2,'x','y','z'])

s.rolling(2).min()

0    3
1    1
2    2
3    x
4    y
5    z
dtype: object

Problem description

Should raise an exception because the series contains objects. Instead, function returns the series.

@gojandrooo gojandrooo changed the title Confusing min( Confusing - rolling min( ) function "accepting" objects Mar 10, 2018
@jorisvandenbossche
Copy link
Member

Thanks for the report!

This is certainly a bug, as it is not even calculating a minimum for the numerical values. Didn't look in detail, but I suppose this is due to the automatic skipping of non-numerical columns.
In case of a DataFrame that is useful:

In [3]: pd.DataFrame({'a': [1,2,3,4], 'b':[1,2,'a', 'b']}).rolling(2).min()
Out[3]: 
     a  b
0  NaN  1
1  1.0  2
2  2.0  a
3  3.0  b

but in case of a Series, just passing it through makes less sense.

@jorisvandenbossche
Copy link
Member

Related issues: #18129, #15085

@ihsansecer
Copy link
Contributor

ihsansecer commented Jul 6, 2019

This is working fine on master

>>> pd.DataFrame({'a': [1,2,3,4], 'b':[1,2,'a', 'b']}).rolling(2).min()
     a
0  NaN
1  1.0
2  2.0
3  3.0
>>> s = pd.Series([3,1,2,'x','y','z'])
>>> s.rolling(2).min()
Traceback (most recent call last):
...
pandas.core.base.DataError: No numeric types to aggregate

@jreback
Copy link
Contributor

jreback commented Jul 6, 2019

#27044 was just merged

@jreback jreback closed this as completed Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

5 participants