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

Fix unpacking of median aggregation result #161

Merged
merged 1 commit into from Apr 3, 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
11 changes: 7 additions & 4 deletions eland/operations.py
Expand Up @@ -480,7 +480,6 @@ def aggs(self, query_compiler, pd_aggs):
field_names = query_compiler.get_field_names(include_scripted_fields=False)

body = Query(query_params["query"])

# convert pandas aggs to ES equivalent
es_aggs = self._map_pd_aggs_to_es_aggs(pd_aggs)

Expand Down Expand Up @@ -509,9 +508,13 @@ def aggs(self, query_compiler, pd_aggs):
values = list()
for es_agg in es_aggs:
if isinstance(es_agg, tuple):
values.append(
response["aggregations"][es_agg[0] + "_" + field][es_agg[1]]
)
agg_value = response["aggregations"][es_agg[0] + "_" + field]

# Pull multiple values from 'percentiles' result.
if es_agg[0] == "percentiles":
agg_value = agg_value["values"]

values.append(agg_value[es_agg[1]])
else:
values.append(
response["aggregations"][es_agg + "_" + field]["value"]
Expand Down
19 changes: 19 additions & 0 deletions eland/tests/dataframe/test_aggs_pytest.py
Expand Up @@ -68,3 +68,22 @@ def test_terms_aggs(self):
print(ed_sum_min_std.dtypes)

assert_almost_equal(pd_sum_min_std, ed_sum_min_std, check_less_precise=True)

def test_aggs_median_var(self):
pd_ecommerce = self.pd_ecommerce()
ed_ecommerce = self.ed_ecommerce()

pd_aggs = pd_ecommerce[
["taxful_total_price", "taxless_total_price", "total_quantity"]
].agg(["median", "var"])
ed_aggs = ed_ecommerce[
["taxful_total_price", "taxless_total_price", "total_quantity"]
].agg(["median", "var"])

print(pd_aggs, pd_aggs.dtypes)
print(ed_aggs, ed_aggs.dtypes)

# Eland returns all float values for all metric aggs, pandas can return int
# TODO - investigate this more
pd_aggs = pd_aggs.astype("float64")
assert_almost_equal(pd_aggs, ed_aggs, check_less_precise=2)