Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sharepa/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def bucket_to_dataframe(name, buckets, append_name=None):
single_dict = item.to_dict()
single_dict[name] = single_dict.pop('doc_count')
if append_name:
for key in single_dict.keys():
persistance_dict = single_dict.copy()
for key in persistance_dict.keys():
single_dict[append_name + '.' + key] = single_dict.pop(key)
expanded_buckets.append(single_dict)
return pd.DataFrame(expanded_buckets)
Expand All @@ -37,7 +38,10 @@ def agg_to_two_dim_dataframe(agg):
if dict not in [type(item) for item in bucket_as_dict.values()]:
return bucket_to_dataframe('doc_count', agg.buckets)
else:
name_of_lower_level = bucket_as_dict.keys()[0]
lower_level_dict = [item for item in bucket_as_dict.keys() if type(bucket_as_dict[item]) is dict]
if len(lower_level_dict) > 1:
raise ValueError('Two dimensional data can only convert a 2 level aggregation (with 1 aggregation at each level)')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test that causes this error to be raised? You can assert that certain errors are thrown with the assert_raises pytest function:

import pytest

def test_zero_division():
    with pytest.raises(ZeroDivisionError):
        1 / 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done...

name_of_lower_level = lower_level_dict[0]
single_level_dataframe = bucket_to_dataframe(bucket.key,
bucket[name_of_lower_level]['buckets'],
name_of_lower_level)
Expand Down
Loading