From 9b551dd879a0957990bf9e46fbdcb81400ec3a50 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Thu, 27 Jun 2019 15:09:33 -0500 Subject: [PATCH] review comments --- pandas/core/groupby/generic.py | 2 +- pandas/tests/sparse/test_pivot.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 60dc2aadb5ca48..d736f41878c2a2 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -158,7 +158,7 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, s = groupby(obj, self.grouper) try: result = s.aggregate(lambda x: alt(x, axis=self.axis)) - except Exception: + except TypeError: # we may have an exception in trying to aggregate # continue and exclude the block pass diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index 1841571eb61c83..8f98117f20208f 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -42,12 +42,12 @@ def test_pivot_table(self): values='E', aggfunc='mean') tm.assert_frame_equal(res_sparse, res_dense) - # ToDo: sum doesn't handle nan properly - # res_sparse = pd.pivot_table(self.sparse, index='A', columns='B', - # values='E', aggfunc='sum') - # res_dense = pd.pivot_table(self.dense, index='A', columns='B', - # values='E', aggfunc='sum') - # tm.assert_frame_equal(res_sparse, res_dense) + def test_pivot_table_with_nans(self): + res_sparse = pd.pivot_table(self.sparse, index='A', columns='B', + values='E', aggfunc='sum') + res_dense = pd.pivot_table(self.dense, index='A', columns='B', + values='E', aggfunc='sum') + tm.assert_frame_equal(res_sparse, res_dense) @pytest.mark.xfail(not _np_version_under1p17, reason="failing occasionally on numpy > 1.17",