Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(target-s3-parquet): add a function to conver Decimal values #39

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading