Skip to content

Commit

Permalink
fix(target-s3-parquet): add a function to conver Decimal values
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos314 committed Jan 31, 2024
1 parent ba19a66 commit 825ab36
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion target_s3_parquet/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
import numpy as np
import json
from typing import List
from decimal import Decimal


def _remove_nulls(array):
return [v for v in array if v != "null"]


def _convert_decimal(value):
if isinstance(value, Decimal):
return str(value)
return value


def get_valid_types(types):
if isinstance(types, list):
return _remove_nulls(types)[0]
Expand Down Expand Up @@ -47,7 +54,9 @@ def apply_json_dump_to_df(
valid_attributes = get_valid_attributes(attributes_names, df)
if len(valid_attributes) > 0:
for attribute in valid_attributes:
df.loc[:, attribute] = df[attribute].apply(lambda x: json.dumps(x))
df.loc[:, attribute] = df[attribute].apply(
lambda x: json.dumps(x, default=_convert_decimal)
)
return df


Expand Down

0 comments on commit 825ab36

Please sign in to comment.