|
9 | 9 | from pandas import (date_range, bdate_range, Timestamp,
|
10 | 10 | Index, MultiIndex, DataFrame, Series,
|
11 | 11 | concat, Panel, DatetimeIndex, read_csv)
|
| 12 | +from pandas.core.dtypes.missing import isna |
12 | 13 | from pandas.errors import UnsupportedFunctionCall, PerformanceWarning
|
13 | 14 | from pandas.util.testing import (assert_frame_equal, assert_index_equal,
|
14 | 15 | assert_series_equal, assert_almost_equal)
|
@@ -2061,6 +2062,27 @@ def test_rank_object_raises(self, ties_method, ascending, na_option,
|
2061 | 2062 | ascending=ascending,
|
2062 | 2063 | na_option=na_option, pct=pct)
|
2063 | 2064 |
|
| 2065 | + @pytest.mark.parametrize("skipna", [True, False]) |
| 2066 | + @pytest.mark.parametrize("vals,exp", [ |
| 2067 | + (['foo', 'bar', 'baz'], True), (['foo', '', ''], True), |
| 2068 | + (['', '', ''], False), ([1, 2, 3], True), ([1, 0, 0], True), |
| 2069 | + ([0, 0, 0], False), ([1., 2., 3.], True), ([1., 0., 0.], True), |
| 2070 | + ([0., 0., 0.], False), ([True, True, True], True), |
| 2071 | + ([True, False, False], True), ([False, False, False], False), |
| 2072 | + ([np.nan, np.nan, np.nan], False) |
| 2073 | + ]) |
| 2074 | + def test_groupby_any(self, skipna, vals, exp): |
| 2075 | + df = DataFrame({'key': ['a'] * 3 + ['b'] * 3, 'val': vals * 2}) |
| 2076 | + |
| 2077 | + # edge case for missing data with skipna=False |
| 2078 | + if not(skipna) and all(isna(vals)): |
| 2079 | + exp = True |
| 2080 | + |
| 2081 | + exp_df = DataFrame([exp] * 2, columns=['val'], index=pd.Index( |
| 2082 | + ['a', 'b'], name='key')) |
| 2083 | + result = df.groupby('key').any(skipna=skipna) |
| 2084 | + assert_frame_equal(result, exp_df) |
| 2085 | + |
2064 | 2086 | def test_dont_clobber_name_column(self):
|
2065 | 2087 | df = DataFrame({'key': ['a', 'a', 'a', 'b', 'b', 'b'],
|
2066 | 2088 | 'name': ['foo', 'bar', 'baz'] * 2})
|
|
0 commit comments