text_extensions_for_pandas/io/watson/tables.py
def _convert_val_to_numeric(val, cast_type=float, regex_exp='[^0-9.-()]'):
    """
    converts a single value to a numeric type as specified, and removes all non-numeric characters
        If this is not possible, a warning is printed to the commandline and pd.NA is returned instead
    :param val: The value to be converted (a string)
    :param cast_type: the type to convert the value to
    :param regex_exp: the regex expression to remove non-numeric characters. this can be changed to change the decimal
                    point or to allow certian special characters
    :return: an int or float, extracted from the input val
    """
    multiplier = 1

    try:
        stripped = regex.sub(regex_exp, '', val)
        if len(stripped) >= 2 and stripped[0] == '(' and stripped[-1] == ')':
            multiplier = multiplier*-1
            ans = cast_type(stripped[1:-1])
        else:
            ans = cast_type(regex.sub(regex_exp, '', val))
        ans = ans * multiplier
    except ValueError:
        ans = pd.NA
        print(f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>")
    except TypeError:
        if type(val) in [float, int, cast_type]:
            ans = cast_type(val)
        else:
            print(f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>")
            ans = pd.NA
    return ans

    converts a single value to a numeric type as specified, and removes all non-numeric characters
        If this is not possible, a warning is printed to the commandline and pd.NA is returned instead
    :param val: The value to be converted (a string)
    :param cast_type: the type to convert the value to
    :param regex_exp: the regex expression to remove non-numeric characters. this can be changed to change the decimal
                    point or to allow certian special characters
    :return: an int or float, extracted from the input val
    
converts a single value to a numeric type as specified, and removes all non-numeric characters
If this is not possible, a warning is printed to the commandline and pd.NA is returned instead
converts a single value to a numeric type as specified and removes all non - numeric characters If this is not possible a warning is printed to the commandline and pd . NA is returned instead
def _convert_val_to_numeric(val, cast_type=float, regex_exp='[^0-9.-()]'):
    multiplier = 1
    try:
        stripped = regex.sub(regex_exp, '', val)
        if len(stripped) >= 2 and stripped[0] == '(' and stripped[-1] == ')':
            multiplier = multiplier*-1
            ans = cast_type(stripped[1:-1])
        else:
            ans = cast_type(regex.sub(regex_exp, '', val))
        ans = ans * multiplier
    except ValueError:
        ans = pd.NA
        print(f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>")
    except TypeError:
        if type(val) in [float, int, cast_type]:
            ans = cast_type(val)
        else:
            print(f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>")
            ans = pd.NA
    return ans
def _convert_val_to_numeric ( val , cast_type = float , regex_exp = '[^0-9.-()]' ) : multiplier = 1 try : stripped = regex . sub ( regex_exp , '' , val ) if len ( stripped ) >= 2 and stripped [ 0 ] == '(' and stripped [ - 1 ] == ')' : multiplier = multiplier * - 1 ans = cast_type ( stripped [ 1 : - 1 ] ) else : ans = cast_type ( regex . sub ( regex_exp , '' , val ) ) ans = ans * multiplier except ValueError : ans = pd . NA print ( f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>" ) except TypeError : if type ( val ) in [ float , int , cast_type ] : ans = cast_type ( val ) else : print ( f"ERROR READING VALUE:\"{val}\"\t Filling with <NA>" ) ans = pd . NA return ans
converts a single value to a numeric type as specified, and removes all non-numeric characters
If this is not possible, a warning is printed to the commandline and pd.NA is returned instead
converts a single value to a numeric type as specified and removes all non - numeric characters If this is not possible a warning is printed to the commandline and pd . NA is returned instead
"""
    converts a single value to a numeric type as specified, and removes all non-numeric characters
        If this is not possible, a warning is printed to the commandline and pd.NA is returned instead
    :param val: The value to be converted (a string)
    :param cast_type: the type to convert the value to
    :param regex_exp: the regex expression to remove non-numeric characters. this can be changed to change the decimal
                    point or to allow certian special characters
    :return: an int or float, extracted from the input val
    """
an int or float, extracted from the input val
an int or float extracted from the input val
val
The value to be converted (a string)
The value to be converted ( a string )
cast_type
the type to convert the value to
the type to convert the value to
regex_exp
the regex expression to remove non-numeric characters. this can be changed to change the decimal
point or to allow certian special characters
the regex expression to remove non - numeric characters . this can be changed to change the decimal point or to allow certian special characters