aboutsummaryrefslogtreecommitdiff
path: root/quality_control/average.py
blob: 06b0a4772f69d9ee1247badaaeab5c0a9a75f4d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Contain logic for checking average files"""
import re
from typing import Union

from .errors import InvalidValue

def invalid_value(line_number: int, column_number: int, val: str) -> Union[
        InvalidValue, None]:
    """Return an `InvalidValue` object if `val` is not a valid "averages"
    value."""
    if re.search(r"^[0-9]+\.[0-9]{3}$", val):
        return None
    if re.search(r"^0\.0+$", val) or re.search("^0+$", val):
        return None
    return InvalidValue(
        line_number, column_number, val, (
            f"Invalid value '{val}'. "
            "Expected string representing a number with exactly three decimal "
            "places."))