mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-11-08 05:43:53 +00:00
fixed csv_string_to_list when data contains null
This commit is contained in:
parent
315f0bf5f9
commit
16d1ae77ee
@ -253,9 +253,23 @@ def list_of_list_to_csv(data: List[List[str]]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def csv_string_to_list(csv_string: str) -> List[List[str]]:
|
def csv_string_to_list(csv_string: str) -> List[List[str]]:
|
||||||
output = io.StringIO(csv_string)
|
# Clean the string by removing NUL characters
|
||||||
reader = csv.reader(output)
|
cleaned_string = csv_string.replace('\0', '')
|
||||||
return [row for row in reader]
|
|
||||||
|
output = io.StringIO(cleaned_string)
|
||||||
|
reader = csv.reader(
|
||||||
|
output,
|
||||||
|
quoting=csv.QUOTE_ALL, # Match the writer configuration
|
||||||
|
escapechar='\\', # Use backslash as escape character
|
||||||
|
quotechar='"', # Use double quotes
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return [row for row in reader]
|
||||||
|
except csv.Error as e:
|
||||||
|
raise ValueError(f"Failed to parse CSV string: {str(e)}")
|
||||||
|
finally:
|
||||||
|
output.close()
|
||||||
|
|
||||||
|
|
||||||
def save_data_to_file(data, file_name):
|
def save_data_to_file(data, file_name):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user