{"record":{"id":"b8edf328482d8f43","repo":"TheAlgorithms/Python","slug":"actual-result-should-be-float-value-passed-is-a-l","errorCode":null,"errorMessage":"Actual result should be float. Value passed is a list","messagePattern":"Actual result should be float\\. Value passed is a list","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"machine_learning/forecasting/run.py","lineNumber":111,"sourceCode":"    iqr = q3 - q1\n    low_lim = q1 - (iqr * 0.1)\n    return float(low_lim)\n\n\ndef data_safety_checker(list_vote: list, actual_result: float) -> bool:\n    \"\"\"\n    Used to review all the votes (list result prediction)\n    and compare it to the actual result.\n    input : list of predictions\n    output : print whether it's safe or not\n    >>> data_safety_checker([2, 3, 4], 5.0)\n    False\n    \"\"\"\n    safe = 0\n    not_safe = 0\n\n    if not isinstance(actual_result, float):\n        raise TypeError(\"Actual result should be float. Value passed is a list\")\n\n    for i in list_vote:\n        if i > actual_result:\n            safe = not_safe + 1\n        elif abs(abs(i) - abs(actual_result)) <= 0.1:\n            safe += 1\n        else:\n            not_safe += 1\n    return safe > not_safe\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    data column = total user in a day, how much online event held in one day,\n    what day is that(sunday-saturday)\n    \"\"\"\n    data_input_df = pd.read_csv(\"ex_data.csv\")\n","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/machine_learning/forecasting/run.py#L93-L129","documentation":"Raised as TypeError by data_safety_checker when actual_result is not a float. The function compares each vote against a scalar actual value with abs(); a list (or int/str) would either do elementwise comparison or raise later, so the type is enforced up front. Note the check is strict isinstance, so ints are rejected too.","triggerScenarios":"Calling data_safety_checker(votes, [1.0, 2.0]) by swapping arguments, or passing an int like data_safety_checker(votes, 5) — both fail isinstance(actual_result, float).","commonSituations":"Argument order confusion since both parameters are positional; passing numpy floats (np.float64 IS a float subclass, so it passes) but passing np.float32 fails; passing the raw prediction list instead of the scalar actual value.","solutions":["Pass the arguments in the right order: list_vote first, then the scalar actual_result.","Coerce to float explicitly: data_safety_checker(votes, float(actual_value)).","If actual_result is an array of one element, index it first (as run.py does with test_user[0])."],"exampleFix":"# before\ndata_safety_checker([2, 3, 4], test_user)  # test_user is a list\n\n# after\ndata_safety_checker([2, 3, 4], float(test_user[0]))","handlingStrategy":"type-guard","validationCode":"actual = float(np.asarray(actual_result).reshape(-1)[0])\nsafe = data_safety_checker(list_vote, actual)","typeGuard":"def is_scalar_float(v) -> bool:\n    return isinstance(v, float) and not isinstance(v, bool)","tryCatchPattern":"try:\n    data_safety_checker(votes, actual_result)\nexcept TypeError as e:\n    if \"should be float\" in str(e):\n        data_safety_checker(votes, float(np.ravel(actual_result)[0]))\n    else:\n        raise","preventionTips":["Keep the argument order straight: (votes_list, actual_scalar).","Coerce scalars with float(...) at the call site.","Index single-element arrays before passing them."],"tags":["machine-learning","forecasting","typeerror","argument-order"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}