feat: implement effective CSV delimiter resolution for imports
- Added `resolve_effective_csv_delimiter` function to determine the correct delimiter based on the uploaded file and template. - Updated CSV import logic to utilize the new delimiter resolution method, ensuring accurate parsing of CSV files with varying delimiters. - Enhanced documentation to reflect changes in delimiter handling. - Added unit tests for the new delimiter resolution functionality.
This commit is contained in:
1 parent
0ad3ddd627
commit
7226e04e9c
5 files changed
+63
-3
No files matched your search
@@ -29,6 +29,7 @@ from csv_parser.core import (
|
||||
iter_csv_dict_rows,
|
||||
normalize_header_for_signature,
|
||||
parse_csv_sample,
|
||||
resolve_effective_csv_delimiter,
|
||||
)
|
||||
from csv_parser.type_converter import build_row_after_mapping, diagnose_row_mapping
|
||||
from csv_parser.field_units import source_unit_choices_for_field
|
||||
@@ -393,7 +394,8 @@ async def csv_import_diagnose(
|
||||
tc = m.get("type_conversions")
|
||||
if not isinstance(tc, dict):
|
||||
tc = {}
|
||||
delim = str(m.get("delimiter") or ",")
|
||||
tpl_delim = str(m.get("delimiter") or ",").strip() or ","
|
||||
delim = resolve_effective_csv_delimiter(text, tpl_delim)
|
||||
exec_module = str(m["module"])
|
||||
|
||||
rows_out: list[dict[str, Any]] = []
|
||||
@@ -418,6 +420,7 @@ async def csv_import_diagnose(
|
||||
"mapping_id": mapping_id,
|
||||
"mapping_name": m.get("mapping_name"),
|
||||
"module": exec_module,
|
||||
"delimiter_template": tpl_delim,
|
||||
"delimiter_used": delim,
|
||||
"has_header": bool(m.get("has_header", True)),
|
||||
"rows_diagnosed": len(rows_out),
|
||||
|
||||
Reference in new issue
Block a user