feat: implement effective CSV delimiter resolution for imports
Deploy Development / deploy (push) Successful in 1m0s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- 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:
Lars committed 2026-04-18 10:12:33 +02:00
1 parent 0ad3ddd627
commit 7226e04e9c
5 files changed
+63 -3

No files matched your search

+15
View File
@@ -11,6 +11,7 @@ from csv_parser.core import (
headers_signature_rank_metrics,
get_csv_import_limits,
iter_csv_dict_rows,
resolve_effective_csv_delimiter,
)
from csv_parser.field_units import source_unit_choices_for_field
from csv_parser.mapping_suggest import build_type_conversions_for_mapping
@@ -29,6 +30,20 @@ def test_sniff_delimiter():
assert sniff_delimiter("a,b,c") == ","
def test_resolve_effective_csv_delimiter_semicolon_file_comma_template():
"""DE-Apple: «;» in der Datei, englische Vorlage speichert «,»."""
header = "Workout Type;Start;End;Duration;Aktive Energie (kJ)"
row = "Laufen;2026-04-17 16:25;2026-04-17 17:00;00:30:00;500"
text = header + "\n" + row + "\n"
assert resolve_effective_csv_delimiter(text, ",") == ";"
assert resolve_effective_csv_delimiter(text, None) == ";"
def test_resolve_effective_csv_delimiter_comma_file_keeps_template():
text = "Workout Type,Start,End\nWalk,2026-04-17 16:25,2026-04-17 17:00\n"
assert resolve_effective_csv_delimiter(text, ",") == ","
def test_parse_csv_sample_header():
text = "Date;kcal\n2024-01-01;2000\n"
headers, rows, delim = parse_csv_sample(text, delimiter=";", max_data_rows=3)