Skip to content

Commit

Permalink
Merge pull request #104 from edanalytics/fix/nested_json_in_template
Browse files Browse the repository at this point in the history
fix nested json not working when rendering destination templates
  • Loading branch information
tomreitz authored Jun 18, 2024
2 parents 6f1baad + f36db9a commit f709b10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<summary>Released 2024-06-18</summary>

* hotfix: Resolve incompatible package dependencies
* hotfix: Fix type casting of nested JSON for destination templates

</details>

Expand Down
8 changes: 6 additions & 2 deletions earthmover/nodes/destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def execute(self, **kwargs):
self.size = os.path.getsize(self.file)

def render_row(self, row: pd.Series):
row = row.astype("string").fillna('')
_data_tuple = row.to_dict()
row = row.to_dict()
types_to_cast = [bool, int, float]
keys_to_cast = list(filter(lambda x: type(row[x]) in types_to_cast, row.keys()))
# this line (a) converts the keys_to_cast to string, and also converts all Nones to empty string:
row = dict(map(lambda x: (x[0], str(x[1]) if x[0] in keys_to_cast else (x[1] if x[1] else "")), row.items()))
_data_tuple = row
_data_tuple["__row_data__"] = row

try:
Expand Down

0 comments on commit f709b10

Please sign in to comment.