diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index cc3bf696ee4c7..be2be9484adc5 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -464,3 +464,6 @@ Bug Fixes - Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`) + +- Bug in ``resample().median()`` if duplicate column names were present (:issue:`14233`) + diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 3bbf248ece1d3..81f85d0ed623b 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -2203,7 +2203,6 @@ def agg_series(self, obj, func): # cython aggregation _cython_functions = copy.deepcopy(BaseGrouper._cython_functions) - _cython_functions['aggregate'].pop('median') class Grouping(object): diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py index fbf0e0095a2f9..56953541265a6 100755 --- a/pandas/tseries/tests/test_resample.py +++ b/pandas/tseries/tests/test_resample.py @@ -2931,6 +2931,20 @@ def test_consistency_with_window(self): self.assertEqual(result.index.nlevels, 2) tm.assert_index_equal(result.index.levels[0], expected) + def test_median_duplicate_columns(self): + # GH 14233 + + df = pd.DataFrame(np.random.randn(20, 3), + columns=list('aaa'), + index=pd.date_range('2012-01-01', + periods=20, freq='s')) + df2 = df.copy() + df2.columns = ['a', 'b', 'c'] + expected = df2.resample('5s').median() + result = df.resample('5s').median() + expected.columns = result.columns + assert_frame_equal(result, expected) + class TestTimeGrouper(tm.TestCase): def setUp(self):