Skip to content

Commit 84bc3b2

Browse files
Dr-Irvjreback
authored andcommitted
BUG: GH14233 resample().median() failed if duplicate column names wer…
Simple fix for median issue. Should use cython implementation. closes #14233 Author: Dr-Irv <[email protected]> Closes #15202 from Dr-Irv/Issue14233 and squashes the following commits: 6e0d900 [Dr-Irv] Use randn in test 1a3b4aa [Dr-Irv] BUG: GH14233 resample().median() failed if duplicate column names were present
1 parent 3ac83eb commit 84bc3b2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ Bug Fixes
433433

434434
- Bug in ``.to_json()`` where ``lines=True`` and contents (keys or values) contain escaped characters (:issue:`15096`)
435435
- Bug in ``.rolling/expanding()`` functions where ``count()`` was not counting ``np.Inf``, nor handling ``object`` dtypes (:issue:`12541`)
436+
- Bug in ``DataFrame.resample().median()`` if duplicate column names are present (:issue:`14233`)
436437

437438
- Bug in ``DataFrame.groupby().describe()`` when grouping on ``Index`` containing tuples (:issue:`14848`)
438439
- Bug in creating a ``MultiIndex`` with tuples and not passing a list of names; this will now raise ``ValueError`` (:issue:`15110`)

pandas/core/groupby.py

-1
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,6 @@ def agg_series(self, obj, func):
22052205
# cython aggregation
22062206

22072207
_cython_functions = copy.deepcopy(BaseGrouper._cython_functions)
2208-
_cython_functions['aggregate'].pop('median')
22092208

22102209

22112210
class Grouping(object):

pandas/tseries/tests/test_resample.py

+14
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,20 @@ 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.random.randn(20, 3),
2938+
columns=list('aaa'),
2939+
index=pd.date_range('2012-01-01',
2940+
periods=20, freq='s'))
2941+
df2 = df.copy()
2942+
df2.columns = ['a', 'b', 'c']
2943+
expected = df2.resample('5s').median()
2944+
result = df.resample('5s').median()
2945+
expected.columns = result.columns
2946+
assert_frame_equal(result, expected)
2947+
29342948

29352949
class TestTimeGrouper(tm.TestCase):
29362950
def setUp(self):

0 commit comments

Comments
 (0)