diff --git a/CosmoTech_Acceleration_Library/Modelops/core/common/writer/CsvWriter.py b/CosmoTech_Acceleration_Library/Modelops/core/common/writer/CsvWriter.py index 31eb751f..26004583 100644 --- a/CosmoTech_Acceleration_Library/Modelops/core/common/writer/CsvWriter.py +++ b/CosmoTech_Acceleration_Library/Modelops/core/common/writer/CsvWriter.py @@ -2,6 +2,8 @@ # Licensed under the MIT license. import csv import logging +import json +import ast from redis.commands.graph.query_result import QueryResult @@ -21,6 +23,8 @@ def _to_csv_format(val: any) -> str: return str(val).lower() if str(val) == 'True' or str(val) == 'False': return str(val).lower() + if str(val).startswith('{') and str(val).endswith('}'): + return json.dumps(ast.literal_eval(str(val))) return str(val) @staticmethod @@ -45,7 +49,7 @@ def write_twin_data(export_dir: str, file_name: str, query_result: QueryResult, output_file_name = f'{export_dir}/{file_name}.csv' logger.debug(f"Writing CSV file {output_file_name}") with open(output_file_name, 'w') as csvfile: - csv_writer = csv.DictWriter(csvfile, fieldnames=headers, delimiter=delimiter, quotechar=quote_char, quoting=csv.QUOTE_ALL) + csv_writer = csv.DictWriter(csvfile, fieldnames=headers, delimiter=delimiter, quotechar=quote_char, quoting=csv.QUOTE_MINIMAL) csv_writer.writeheader() csv_writer.writerows(rows) logger.debug(f"... CSV file {output_file_name} has been written") @@ -64,7 +68,7 @@ def write_relationship_data(export_dir: str, file_name: str, query_result: Query output_file_name = export_dir + file_name + '.csv' logger.debug(f"Writing CSV file {output_file_name}") with open(output_file_name, 'w') as csvfile: - csv_writer = csv.DictWriter(csvfile, fieldnames=headers, delimiter=delimiter, quotechar=quote_char, quoting=csv.QUOTE_ALL) + csv_writer = csv.DictWriter(csvfile, fieldnames=headers, delimiter=delimiter, quotechar=quote_char, quoting=csv.QUOTE_MINIMAL) csv_writer.writeheader() csv_writer.writerows(rows) logger.debug(f"... CSV file {output_file_name} has been written") diff --git a/CosmoTech_Acceleration_Library/__init__.py b/CosmoTech_Acceleration_Library/__init__.py index 1b1b67dc..38312a72 100644 --- a/CosmoTech_Acceleration_Library/__init__.py +++ b/CosmoTech_Acceleration_Library/__init__.py @@ -1,4 +1,4 @@ # Copyright (c) Cosmo Tech corporation. # Licensed under the MIT license. -__version__ = '0.2.15' +__version__ = '0.2.16'