fixes division by zero error for kurt() by mortada · Pull Request #9197 · pandas-dev/pandas (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation7 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

mortada

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

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

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

@jreback

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

@mortada

@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

@mortada

@jreback PR is updated, please take a look

@shoyer

shoyer added a commit that referenced this pull request

Jan 5, 2015

@shoyer

fixes division by zero error for kurt()

@shoyer

@mortada mortada deleted the kurt_corner_cases branch

April 29, 2015 15:32