feat(csv-parser): Enhance CSV parsing with header normalization and flexible date handling
- Added a new function to strip header keys of unwanted characters, improving CSV import consistency. - Updated CSV row iteration to utilize the new header normalization function, ensuring cleaner data processing. - Enhanced date parsing capabilities to support flexible formats, accommodating various date representations in CSV files. - Introduced additional tests to validate the new header normalization and date parsing functionalities.
This commit is contained in:
1 parent
5e5f3b4e5a
commit
338163ac0b
3 files changed
+403
-42
No files matched your search
@@ -138,6 +138,12 @@ def get_csv_import_limits(conn_row: dict | None) -> dict[str, int]:
|
||||
return defaults
|
||||
|
||||
|
||||
def _strip_header_key(k: str | None) -> str:
|
||||
if k is None:
|
||||
return ""
|
||||
return str(k).strip().removeprefix("\ufeff")
|
||||
|
||||
|
||||
def iter_csv_dict_rows(
|
||||
text: str,
|
||||
delimiter: str,
|
||||
@@ -154,4 +160,4 @@ def iter_csv_dict_rows(
|
||||
continue
|
||||
if not any(v and str(v).strip() for v in row.values()):
|
||||
continue
|
||||
yield {k: (v or "").strip() for k, v in row.items()}
|
||||
yield {_strip_header_key(k): (v or "").strip() for k, v in row.items() if _strip_header_key(k)}
|
||||
Reference in new issue
Block a user