Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SimStadt
simstadtpy
Commits
aecc7f62
Commit
aecc7f62
authored
Aug 06, 2026
by
Eric Duminil
Browse files
Hopefully fixing detect_decimal
parent
58d0fd82
Changes
1
Show whitespace changes
Inline
Side-by-side
src/simstadt/results/base.py
View file @
aecc7f62
...
@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
...
@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
def
detect_decimal
(
csv_path
:
Path
,
line_number
:
int
,
check
:
str
=
""
)
->
str
:
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)
"""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
Check if substring check is included in line at line_number
"""
"""
with
open
(
csv_path
,
encoding
=
"utf-8"
)
as
csv
:
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:
...
@@ -26,7 +28,7 @@ def detect_decimal(csv_path: Path, line_number: int, check: str = "") -> str:
if
check
and
(
check
not
in
line
):
if
check
and
(
check
not
in
line
):
raise
ValueError
(
f
"Couldn't find '
{
check
}
' in '
{
line
}
'."
)
raise
ValueError
(
f
"Couldn't find '
{
check
}
' in '
{
line
}
'."
)
possible_delimiters
=
[
"."
,
","
]
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
)
logger
.
debug
(
"Decimal for %s is '%s'"
,
csv_path
.
name
,
delimiter
)
return
delimiter
return
delimiter
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment