Commit 5a33dbf2 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

make histogram analysis json serializable

parent bce808ca
Pipeline #5931 failed with stages
in 38 minutes and 5 seconds
...@@ -50,8 +50,8 @@ class HistogramTask(AnalyticTask): ...@@ -50,8 +50,8 @@ class HistogramTask(AnalyticTask):
(df['subset'] == subset)] (df['subset'] == subset)]
values = sub_df['value'] values = sub_df['value']
hist, bin_edges = np.histogram(values) hist, bin_edges = np.histogram(values)
hist = list(hist) hist = hist.tolist()
bin_edges = list(bin_edges) bin_edges = bin_edges.tolist()
mean = np.mean(values) mean = np.mean(values)
median = np.median(values) median = np.median(values)
variance = np.var(values) variance = np.var(values)
......
import json
import pytest import pytest
import pandas as pd import pandas as pd
...@@ -172,3 +174,32 @@ class TestHistogramTask: ...@@ -172,3 +174,32 @@ class TestHistogramTask:
data=df, data=df,
categories=[cat_df]) categories=[cat_df])
assert 'selected numerical variable must be non-empty' in e assert 'selected numerical variable must be non-empty' in e
def test_output_is_json_serializable(self):
df = pd.DataFrame([[100, 'foo', 1],
[101, 'foo', 2],
[102, 'foo', 3],
[103, 'foo', 4],
[104, 'foo', 5],
[105, 'foo', 6],
[106, 'foo', 7],
[107, 'foo', 8],
[108, 'foo', 9],
[109, 'foo', 10]],
columns=['id', 'feature', 'value'])
cat_df = pd.DataFrame([[100, 'cat', 'A'],
[101, 'cat', 'B'],
[102, 'cat', 'A'],
[103, 'cat', 'B'],
[104, 'cat', 'A'],
[105, 'cat', 'B'],
[106, 'cat', 'A'],
[107, 'cat', 'B'],
[108, 'cat', 'A'],
[109, 'cat', 'B']],
columns=['id', 'feature', 'value'])
result = self.task.main(id_filter=[],
subsets=[],
data=df,
categories=[cat_df])
json.dumps(result)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment