# Path: bamboo/lib/mongo.py
# def dump_mongo_json(obj):
#     """Dump JSON using BSON conversion.
# 
#     Args:
# 
#     :param obj: Datastructure to dump as JSON.
# 
#     :returns: JSON string of dumped `obj`.
#     """
#     return json.dumps(obj, default=json_util.default)
# 
# Path: bamboo/lib/utils.py
# def is_float_nan(num):
#     """Return True is `num` is a float and NaN."""
#     return isinstance(num, float) and isnan(num)


from bson import json_util
from bamboo.lib.mongo import dump_mongo_json
from bamboo.lib.utils import is_float_nan
import numpy as np
import simplejson as json



# JSON encoding string
JSON_NULL = 'null'


class JSONError(Exception):
    """For errors while parsing JSON."""
    pass


def df_to_jsondict(df):
    """Return DataFrame as a list of dicts for each row."""
    return [series_to_jsondict(series) for _, series in df.iterrows()]


def df_to_json(df):
    """Convert DataFrame to a list of dicts, then dump to JSON."""
    jsondict = df_to_jsondict(df)

# Path: bamboo/lib/mongo.py
# def dump_mongo_json(obj):
#     """Dump JSON using BSON conversion.
# 
#     Args:
# 
#     :param obj: Datastructure to dump as JSON.
# 
#     :returns: JSON string of dumped `obj`.
#     """
#     return json.dumps(obj, default=json_util.default)
# 
# Path: bamboo/lib/utils.py
# def is_float_nan(num):
#     """Return True is `num` is a float and NaN."""
#     return isinstance(num, float) and isnan(num)


# Path: bamboo/lib/jsontools.py
from bson import json_util
from bamboo.lib.mongo import dump_mongo_json
from bamboo.lib.utils import is_float_nan
import numpy as np
import simplejson as json




# JSON encoding string
JSON_NULL = 'null'


class JSONError(Exception):
    """For errors while parsing JSON."""
    pass


def df_to_jsondict(df):
    """Return DataFrame as a list of dicts for each row."""
    return [series_to_jsondict(series) for _, series in df.iterrows()]


def df_to_json(df):
    """Convert DataFrame to a list of dicts, then dump to JSON."""
    jsondict = df_to_jsondict(df)

    return dump_mongo_json(jsondict)