Skip to content

BUG: GH14233 resample().median() failed if duplicate column names wer… #15202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

1 change: 0 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,6 @@ def agg_series(self, obj, func):
# cython aggregation

_cython_functions = copy.deepcopy(BaseGrouper._cython_functions)
_cython_functions['aggregate'].pop('median')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I remember something was failing because of this.......

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran nosetests locally, and it works. I looked back at old versions, and I think it is a legacy issue of how the cython stuff was implemented over time.


class Grouping(object):
Expand Down
14 changes: 14 additions & 0 deletions pandas/tseries/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down