Skip to content

Commit

Permalink
Added json function to better handle jsons with nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
argenisleon committed Nov 24, 2019
1 parent 20718db commit 33eea4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion optimus/helpers/json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json

import simplejson as json


def json_converter(obj):
Expand All @@ -22,3 +23,7 @@ def json_enconding(obj):
:return:
"""
return json.dumps(obj, default=json_converter)


def dump_json(value):
return json.dumps(value, ignore_nan=True, default=json_converter)
6 changes: 3 additions & 3 deletions optimus/profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from optimus.helpers.constants import RELATIVE_ERROR, Actions, PYSPARK_NUMERIC_TYPES, PYTHON_TO_PROFILER
from optimus.helpers.decorators import time_it
from optimus.helpers.functions import absolute_path, update_dict
from optimus.helpers.json import json_converter
from optimus.helpers.json import json_converter, dump_json
from optimus.helpers.logger import logger
from optimus.helpers.output import print_html
from optimus.helpers.raiseit import RaiseIt
Expand Down Expand Up @@ -365,7 +365,7 @@ def dataset(self, df, columns="*", buckets=10, infer=False, relative_error=RELAT

# col_names = output_columns["columns"].keys()
if format == "json":
result = json.dumps(output_columns, ignore_nan=True, default=json_converter)
result = dump_json(output_columns)
else:
result = output_columns

Expand All @@ -386,6 +386,7 @@ def columns_stats(self, df, columns, buckets=10, infer=False, relative_error=REL
0 more precision/slow 1 less precision/faster
:param approx_count: Use the function approx_count_distinct or countDistinct. approx_count_distinct is faster
:param mismatch:
:param advanced_stats:
:return: json object
"""

Expand Down Expand Up @@ -585,7 +586,6 @@ def extra_columns_stats(df, col_name, stats):

return result


@staticmethod
def missing_values(df, columns):
"""
Expand Down

0 comments on commit 33eea4f

Please sign in to comment.