Skip to content

Commit 32f2b3b

Browse files
fix: update detect delimiter
Co-authored-by: Carlos López-Elorduy <107858804+CarlosLopezElorduy@users.noreply.github.com>
1 parent 7a78ba0 commit 32f2b3b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

openvariant/variant/variant.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ def _open_file(file_path: str, mode='r+b'):
3838
return mm, file
3939

4040
def _detect_delimiter(line: str):
41-
"""Detects the dominant delimiter in a line"""
42-
counts = {
43-
'\t': line.count('\t'),
44-
',': line.count(','),
45-
';': line.count(';')
46-
}
47-
return max(counts, key=counts.get)
41+
sniffer = csv.Sniffer()
42+
dialect = sniffer.sniff(line, delimiters='\t,;')
43+
return dialect.delimiter
4844

4945
def _base_parser(mm_obj: mmap, file_path: str, delimiter: str, skip_files: bool) -> Generator[int, str, None]:
5046
"""Cleaning comments and irrelevant data"""

0 commit comments

Comments
 (0)