Skip to content
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

fixes division by zero error for kurt() #9197

Merged
merged 1 commit into from
Jan 5, 2015

Conversation

mortada
Copy link
Contributor

@mortada mortada commented Jan 4, 2015

Currently if kurt() is called on a Series with equal values, it throws a ZeroDivisionError

In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: s = pd.Series(np.ones(5))
In [4]: s.kurt()
ZeroDivisionError: float division by zero

This is not consistent with the case when kurt() is called on a DataFrame of equal values

In [5]: df = pd.DataFrame(np.ones((5, 5)))
In [6]: df.kurt()
Out[6]:
0    0
1    0
2    0
3    0
4    0
dtype: float64

with this patch s.kurt() will return 0 instead of throwing.

@shoyer shoyer added Bug Numeric Operations Arithmetic, Comparison, and Logical operations labels Jan 4, 2015
@shoyer
Copy link
Member

shoyer commented Jan 4, 2015

This looks good to me.

@mortada could you please add a note to the what's new for 0.16? You can reference the issue number for this PR.

@mortada
Copy link
Contributor Author

mortada commented Jan 5, 2015

@shoyer sure I've added a note to whatsnew for 0.16, this PR is updated.

@jreback
Copy link
Contributor

jreback commented Jan 5, 2015

is skew ok? are there similar tests? if not can you add

@mortada
Copy link
Contributor Author

mortada commented Jan 5, 2015

@jreback skew() doesn't have this problem.

In [4]: for i in range(1, 5):
    print 'i is %d, skew is %f' % (i, pd.Series(np.ones(i)).skew())
   ...:
i is 1, skew is nan
i is 2, skew is nan
i is 3, skew is 0.000000
i is 4, skew is 0.000000

and sure I will add similar tests to skew

@mortada
Copy link
Contributor Author

mortada commented Jan 5, 2015

@jreback PR is updated, please take a look

@shoyer
Copy link
Member

shoyer commented Jan 5, 2015

Lgtm

shoyer added a commit that referenced this pull request Jan 5, 2015
fixes division by zero error for kurt()
@shoyer shoyer merged commit 3afd6c7 into pandas-dev:master Jan 5, 2015
@shoyer
Copy link
Member

shoyer commented Jan 5, 2015

Thanks!

@mortada mortada deleted the kurt_corner_cases branch April 29, 2015 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants