Skip to content

Commit 8356d99

Browse files
committed
ENH: added tests for the new kurtosis functionality - fixes pandas-dev#40139
1 parent fd0dd18 commit 8356d99

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

pandas/tests/groupby/test_groupby.py

+61
Original file line numberDiff line numberDiff line change
@@ -2189,3 +2189,64 @@ def test_groupby_mean_duplicate_index(rand_series_with_duplicate_datetimeindex):
21892189
result = dups.groupby(level=0).mean()
21902190
expected = dups.groupby(dups.index).mean()
21912191
tm.assert_series_equal(result, expected)
2192+
2193+
def test_groupby_aggregateby_count_mean_kurtosis():
2194+
df = pd.DataFrame({'bird':['Falcon', 'Falcon', 'Falcon', 'Falcon',
2195+
'Parrot', 'Parrot', 'Parrot', 'Parrot'],
2196+
'value': [390., 350.,390., 350.,
2197+
30., 20., 30., 20.]})
2198+
result = df.groupby('bird').aggregate({'value': ['count', 'mean','kurtosis']})
2199+
expected = np.array([[4,370.0,-6.0],[4,25.0,-6.0]])
2200+
numpyresult = result.to_numpy()
2201+
tm.assert_numpy_array_equal(numpyresult,expected)
2202+
2203+
def test_groupby_aggregateby_kurtosis():
2204+
df = pd.DataFrame({'bird':['Falcon', 'Falcon', 'Falcon', 'Falcon',
2205+
'Parrot', 'Parrot', 'Parrot', 'Parrot'],
2206+
'value': [390., 350.,390., 350.,
2207+
30., 20., 30., 20.]})
2208+
result = df.groupby('bird').aggregate({'value': ['kurtosis']})
2209+
expected = np.array([[-6.0],[-6.0]])
2210+
numpyresult = result.to_numpy()
2211+
tm.assert_numpy_array_equal(numpyresult, expected)
2212+
2213+
def test_groupby_kurtosis_fisher():
2214+
df = pd.DataFrame({'bird':['Falcon', 'Falcon', 'Falcon', 'Falcon',
2215+
'Parrot', 'Parrot', 'Parrot', 'Parrot'],
2216+
'value': [390., 350.,390., 350.,
2217+
30., 20., 30., 20.]})
2218+
result = df.groupby('bird').kurtosis()
2219+
numpyresult = result.to_numpy()
2220+
expected = np.array([[-6.0],[-6.0]])
2221+
tm.assert_numpy_array_equal(numpyresult,expected)
2222+
2223+
def test_groupby_kurtosis_pearson():
2224+
df = pd.DataFrame({'bird':['Falcon', 'Falcon', 'Falcon', 'Falcon',
2225+
'Parrot', 'Parrot', 'Parrot', 'Parrot'],
2226+
'value': [390., 350.,390., 350.,
2227+
30., 20., 30., 20.]})
2228+
result = df.groupby('bird').kurtosis(how="Pearson")
2229+
expected = np.array([[-9.0],[-9.0]])
2230+
numpyresult = result.to_numpy()
2231+
tm.assert_numpy_array_equal(numpyresult,expected)
2232+
2233+
def test_groupby_kurtosis_exception():
2234+
df = pd.DataFrame({'bird':['Falcon', 'Falcon', 'Falcon', 'Falcon',
2235+
'Parrot', 'Parrot', 'Parrot', 'Parrot'],
2236+
'value': [390., 350.,390., 350.,
2237+
30., 20., 30., 20.]})
2238+
msg = 'error is not a valid argument'
2239+
with pytest.raises(ValueError, match=msg):
2240+
result = df.groupby('bird').kurtosis(how="error").to_numpy()
2241+
2242+
def test_groupby_kurtosis_empty():
2243+
df = pd.DataFrame({'bird':[],
2244+
'value': []})
2245+
result = df.groupby('bird').aggregate({'value':['count','mean','kurtosis']}).to_numpy()
2246+
result1 = df.groupby('bird').kurtosis(how='Fisher').to_numpy()
2247+
result2 = df.groupby('bird').kurtosis(how="Pearson").to_numpy()
2248+
expected = np.array([]).reshape(0,3)
2249+
expected1 = np.array([]).reshape(0,1)
2250+
tm.assert_numpy_array_equal(result1, expected1)
2251+
tm.assert_numpy_array_equal(result2, expected1)
2252+
tm.assert_numpy_array_equal(result,expected)

0 commit comments

Comments
 (0)