Skip to content

Commit

Permalink
added JSONType
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanketh7 committed Oct 18, 2022
1 parent 5ca9305 commit 7d5b8fb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions dataprofiler/data_readers/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

logger = dp_logging.get_child_logger(__name__)

JSONType = Union[str, int, float, bool, None, List['JSONType'], Dict[str, 'JSONType']]

def data_generator(data_list: List[str]) -> Generator[str, None, None]:
"""
Expand Down Expand Up @@ -84,8 +85,8 @@ def convert_int_to_string(x: int) -> str:


def unicode_to_str(
data: Union[str, List, Dict], ignore_dicts: bool = False
) -> Union[str, List, Dict]:
data: JSONType, ignore_dicts: bool = False
) -> JSONType:
"""
Convert data to string representation if it is a unicode string.
Expand All @@ -106,7 +107,7 @@ def unicode_to_str(
# if data is a dictionary
if isinstance(data, dict) and not ignore_dicts:
return {
unicode_to_str(key, ignore_dicts=True): unicode_to_str(
cast(str, unicode_to_str(key, ignore_dicts=True)): unicode_to_str(
value, ignore_dicts=True
)
for key, value in data.items()
Expand All @@ -116,7 +117,7 @@ def unicode_to_str(


def json_to_dataframe(
json_lines: List[Dict],
json_lines: List[JSONType],
selected_columns: Optional[List[str]] = None,
read_in_string: bool = False,
) -> Tuple[pd.DataFrame, pd.Series]:
Expand Down Expand Up @@ -187,7 +188,7 @@ def read_json_df(
each call as well as original dtypes of the dataframe columns.
:rtype: typle(Iterator(pd.DataFrame), pd.Series(dtypes)
"""
lines: List[Dict] = list()
lines: List[JSONType] = list()
k = 0
while True:
try:
Expand All @@ -204,7 +205,7 @@ def read_json_df(
),
ignore_dicts=True,
)
lines.append(cast(Dict, obj))
lines.append(obj)
except ValueError:
pass
# To ignore malformatted lines.
Expand Down

0 comments on commit 7d5b8fb

Please sign in to comment.