Skip to content

Commit 1a3b4aa

Browse files
committed
BUG: GH14233 resample().median() failed if duplicate column names were present
1 parent a1b6587 commit 1a3b4aa

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,6 @@ Bug Fixes
464464

465465

466466
- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)
467+
468+
- Bug in ``resample().median()`` if duplicate column names were present (:issue:`14233`)
469+

pandas/core/groupby.py

-1
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,6 @@ def agg_series(self, obj, func):
22032203
# cython aggregation
22042204

22052205
_cython_functions = copy.deepcopy(BaseGrouper._cython_functions)
2206-
_cython_functions['aggregate'].pop('median')
22072206

22082207

22092208
class Grouping(object):

pandas/tseries/tests/test_resample.py

+15
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,21 @@ def test_consistency_with_window(self):
29312931
self.assertEqual(result.index.nlevels, 2)
29322932
tm.assert_index_equal(result.index.levels[0], expected)
29332933

2934+
def test_median_duplicate_columns(self):
2935+
# GH 14233
2936+
2937+
df = pd.DataFrame(np.array([[i + j for i in range(20)]
2938+
for j in [0, 100, 1000]])
2939+
.T, columns=list('aaa'),
2940+
index=pd.date_range('2012-01-01',
2941+
periods=20, freq='s'))
2942+
df2 = df.copy()
2943+
df2.columns = ['a', 'b', 'c']
2944+
expected = df2.resample('5s').median()
2945+
result = df.resample('5s').median()
2946+
expected.columns = result.columns
2947+
assert_frame_equal(result, expected)
2948+
29342949

29352950
class TestTimeGrouper(tm.TestCase):
29362951
def setUp(self):

0 commit comments

Comments
 (0)