# Path: bamboo/lib/jsontools.py
# def series_to_jsondict(series):
#     """Convert a Series to a dictionary encodable as JSON."""
#     return series if series is None else {
#         unicode(key): get_json_value(value)
#         for key, value in series.iteritems()
#     }
# 
# Path: bamboo/lib/mongo.py
# def dict_from_mongo(_dict):
#     for key, value in _dict.items():
#         if isinstance(value, list):
#             value = [dict_from_mongo(obj)
#                      if isinstance(obj, dict) else obj for obj in value]
#         elif isinstance(value, dict):
#             value = dict_from_mongo(value)
# 
#         if _was_encoded_for_mongo(key):
#             del _dict[key]
#             _dict[_decode_from_mongo(key)] = value
# 
#     return _dict
# 
# def dict_for_mongo(_dict):
#     """Encode all keys in `_dict` for MongoDB."""
#     for key, value in _dict.items():
#         if _is_invalid_for_mongo(key):
#             del _dict[key]
#             key = key_for_mongo(key)
# 
#         if isinstance(value, list):
#             _dict[key] = [dict_for_mongo(obj) if isinstance(obj, dict) else obj
#                           for obj in value]
#         elif isinstance(value, dict):
#             _dict[key] = dict_for_mongo(value)
#         else:
#             _dict[key] = value_for_mongo(value)
# 
#     return _dict
# 
# Path: bamboo/lib/utils.py
# def combine_dicts(*dicts):
#     """Combine dicts with keys in later dicts taking precedence."""
#     return dict(chain(*[_dict.iteritems() for _dict in dicts]))


from bamboo.lib.jsontools import series_to_jsondict
from bamboo.lib.mongo import dict_from_mongo, dict_for_mongo
from bamboo.lib.utils import combine_dicts

    :returns: The appropriate summarization for the type of `dtype`.
    """
    return data.value_counts() if is_factor else data.describe()


def summarizable(dframe, col, groups, dataset):
    """Check if column should be summarized.

    :param dframe: DataFrame to check unique values in.
    :param col: Column to check for factor and number of uniques.
    :param groups: List of groups if summarizing with group, can be empty.
    :param dataset: Dataset to pull schema from.

    :returns: True if column, with parameters should be summarized, otherwise
        False.
    """
    if dataset.is_dimension(col):
        cardinality = dframe[col].nunique() if len(groups) else\
            dataset.cardinality(col)
        if cardinality > MAX_CARDINALITY_FOR_COUNT:
            return False

    return not col in groups


def summarize_df(dframe, dataset, groups=[]):
    """Calculate summary statistics."""
    return {
        col: {

# Path: bamboo/lib/jsontools.py
# def series_to_jsondict(series):
#     """Convert a Series to a dictionary encodable as JSON."""
#     return series if series is None else {
#         unicode(key): get_json_value(value)
#         for key, value in series.iteritems()
#     }
# 
# Path: bamboo/lib/mongo.py
# def dict_from_mongo(_dict):
#     for key, value in _dict.items():
#         if isinstance(value, list):
#             value = [dict_from_mongo(obj)
#                      if isinstance(obj, dict) else obj for obj in value]
#         elif isinstance(value, dict):
#             value = dict_from_mongo(value)
# 
#         if _was_encoded_for_mongo(key):
#             del _dict[key]
#             _dict[_decode_from_mongo(key)] = value
# 
#     return _dict
# 
# def dict_for_mongo(_dict):
#     """Encode all keys in `_dict` for MongoDB."""
#     for key, value in _dict.items():
#         if _is_invalid_for_mongo(key):
#             del _dict[key]
#             key = key_for_mongo(key)
# 
#         if isinstance(value, list):
#             _dict[key] = [dict_for_mongo(obj) if isinstance(obj, dict) else obj
#                           for obj in value]
#         elif isinstance(value, dict):
#             _dict[key] = dict_for_mongo(value)
#         else:
#             _dict[key] = value_for_mongo(value)
# 
#     return _dict
# 
# Path: bamboo/lib/utils.py
# def combine_dicts(*dicts):
#     """Combine dicts with keys in later dicts taking precedence."""
#     return dict(chain(*[_dict.iteritems() for _dict in dicts]))


# Path: bamboo/core/summary.py
from bamboo.lib.jsontools import series_to_jsondict
from bamboo.lib.mongo import dict_from_mongo, dict_for_mongo
from bamboo.lib.utils import combine_dicts


    :returns: The appropriate summarization for the type of `dtype`.
    """
    return data.value_counts() if is_factor else data.describe()


def summarizable(dframe, col, groups, dataset):
    """Check if column should be summarized.

    :param dframe: DataFrame to check unique values in.
    :param col: Column to check for factor and number of uniques.
    :param groups: List of groups if summarizing with group, can be empty.
    :param dataset: Dataset to pull schema from.

    :returns: True if column, with parameters should be summarized, otherwise
        False.
    """
    if dataset.is_dimension(col):
        cardinality = dframe[col].nunique() if len(groups) else\
            dataset.cardinality(col)
        if cardinality > MAX_CARDINALITY_FOR_COUNT:
            return False

    return not col in groups


def summarize_df(dframe, dataset, groups=[]):
    """Calculate summary statistics."""
    return {
        col: {

            SUMMARY: series_to_jsondict(