Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fractalis
fractalis
Commits
5a33dbf2
Commit
5a33dbf2
authored
Jul 26, 2018
by
Sascha Herzinger
Browse files
make histogram analysis json serializable
parent
bce808ca
Pipeline
#5931
failed with stages
in 38 minutes and 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fractalis/analytics/tasks/histogram/main.py
View file @
5a33dbf2
...
...
@@ -50,8 +50,8 @@ class HistogramTask(AnalyticTask):
(
df
[
'subset'
]
==
subset
)]
values
=
sub_df
[
'value'
]
hist
,
bin_edges
=
np
.
histogram
(
values
)
hist
=
l
ist
(
h
ist
)
bin_edges
=
list
(
bin_edges
)
hist
=
h
ist
.
tol
ist
(
)
bin_edges
=
bin_edges
.
tolist
(
)
mean
=
np
.
mean
(
values
)
median
=
np
.
median
(
values
)
variance
=
np
.
var
(
values
)
...
...
tests/unit/analytics/histogram/test_histogram.py
View file @
5a33dbf2
import
json
import
pytest
import
pandas
as
pd
...
...
@@ -172,3 +174,32 @@ class TestHistogramTask:
data
=
df
,
categories
=
[
cat_df
])
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment