Skip to content
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

DataFrame.agg() with single non-list aggregation name now returns series #263

Merged
merged 5 commits into from Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -49,3 +49,4 @@ venv/
ENV/
env.bak/
venv.bak/
.mypy_cache
5 changes: 2 additions & 3 deletions eland/dataframe.py
Expand Up @@ -1386,9 +1386,8 @@ def aggregate(self, func, axis=0, *args, **kwargs):
# ['count', 'mad', 'max', 'mean', 'median', 'min', 'mode', 'quantile',
# 'rank', 'sem', 'skew', 'sum', 'std', 'var', 'nunique']
if isinstance(func, str):
# wrap in list
func = [func]
return self._query_compiler.aggs(func)
# Wrap in list
return self._query_compiler.aggs([func]).squeeze().rename(None)
elif is_list_like(func):
# we have a list!
return self._query_compiler.aggs(func)
Expand Down
33 changes: 31 additions & 2 deletions eland/tests/dataframe/test_aggs_pytest.py
Expand Up @@ -18,8 +18,8 @@
# File called _pytest for PyCharm compatability

import numpy as np
from pandas.testing import assert_frame_equal

from pandas.testing import assert_frame_equal, assert_series_equal
import pytest
from eland.tests.common import TestData


Expand Down Expand Up @@ -94,3 +94,32 @@ def test_aggs_median_var(self):
# TODO - investigate this more
pd_aggs = pd_aggs.astype("float64")
assert_frame_equal(pd_aggs, ed_aggs, check_exact=False, check_less_precise=2)

# If Aggregate is given a string then series is returned.
@pytest.mark.parametrize("agg", ["mean", "min", "max"])
def test_terms_aggs_series(self, agg):
pd_flights = self.pd_flights()
ed_flights = self.ed_flights()

pd_sum_min_std = pd_flights.select_dtypes(include=[np.number]).agg(agg)
ed_sum_min_std = ed_flights.select_dtypes(include=[np.number]).agg(agg)

assert_series_equal(pd_sum_min_std, ed_sum_min_std)

def test_terms_aggs_series_with_single_list_agg(self):
# aggs list with single agg should return dataframe.
pd_flights = self.pd_flights()
ed_flights = self.ed_flights()

pd_sum_min = pd_flights.select_dtypes(include=[np.number]).agg(["mean"])
ed_sum_min = ed_flights.select_dtypes(include=[np.number]).agg(["mean"])

assert_frame_equal(pd_sum_min, ed_sum_min)

# If Wrong Aggregate value is given.
def test_terms_wrongaggs(self):
ed_flights = self.ed_flights()[["FlightDelayMin"]]

match = "('abc', ' not currently implemented')"
with pytest.raises(NotImplementedError, match=match):
ed_flights.select_dtypes(include=[np.number]).agg("abc")