Commit aecc7f62 authored by Eric Duminil's avatar Eric Duminil
Browse files

Hopefully fixing detect_decimal

parent 58d0fd82
......@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
def detect_decimal(csv_path: Path, line_number: int, check: str = "") -> str:
"""Detect whether '.' or ',' is used as decimal separator on the given line. (0-index)
The separator with the highest count is considered a decimal separator.
Note: it could fail if many thousand separators are present.
Check if substring check is included in line at line_number
"""
with open(csv_path, encoding="utf-8") as csv:
......@@ -26,7 +28,7 @@ def detect_decimal(csv_path: Path, line_number: int, check: str = "") -> str:
if check and (check not in line):
raise ValueError(f"Couldn't find '{check}' in '{line}'.")
possible_delimiters = [".", ","]
delimiter = next(d for d in possible_delimiters if d in line)
delimiter = max(possible_delimiters, key=line.count)
logger.debug("Decimal for %s is '%s'", csv_path.name, delimiter)
return delimiter
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment