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 3d93424
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions target_s3_parquet/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
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 +53,7 @@ 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 3d93424

Please sign in to comment.