{"record":{"id":"a7aec7c4c8872706","repo":"TheAlgorithms/Python","slug":"input-series-is-not-valid-valid-series-2-4-6","errorCode":null,"errorMessage":"Input series is not valid, valid series - [2, 4, 6]","messagePattern":"Input series is not valid, valid series - \\[2, 4, 6\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/series/arithmetic.py","lineNumber":30,"sourceCode":"    \"\"\"\n    checking whether the input series is arithmetic series or not\n    >>> is_arithmetic_series([2, 4, 6])\n    True\n    >>> is_arithmetic_series([3, 6, 12, 24])\n    False\n    >>> is_arithmetic_series([1, 2, 3])\n    True\n    >>> is_arithmetic_series(4)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input series is not valid, valid series - [2, 4, 6]\n    >>> is_arithmetic_series([])\n    Traceback (most recent call last):\n        ...\n    ValueError: Input list must be a non empty list\n    \"\"\"\n    if not isinstance(series, list):\n        raise ValueError(\"Input series is not valid, valid series - [2, 4, 6]\")\n    if len(series) == 0:\n        raise ValueError(\"Input list must be a non empty list\")\n    if len(series) == 1:\n        return True\n    common_diff = series[1] - series[0]\n    for index in range(len(series) - 1):\n        if series[index + 1] - series[index] != common_diff:\n            return False\n    return True\n\n\ndef arithmetic_mean(series: list) -> float:\n    \"\"\"\n    return the arithmetic mean of series\n\n    >>> arithmetic_mean([2, 4, 6])\n    4.0\n    >>> arithmetic_mean([3, 6, 9, 12])","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/series/arithmetic.py#L12-L48","documentation":"is_arithmetic_series() in maths/series/arithmetic.py checks whether consecutive differences are constant. Its first guard requires isinstance(series, list); any non-list (int, string, tuple, generator) raises ValueError('Input series is not valid, valid series - [2, 4, 6]') before length is inspected. The message shows an example valid series rather than describing the type failure, which surprises callers expecting a TypeError.","triggerScenarios":"Calling is_arithmetic_series(4), is_arithmetic_series('123'), is_arithmetic_series((2, 4, 6)) (tuples are rejected too), or passing a range/iterator/generator object.","commonSituations":"Passing tuples or ranges that 'feel like' sequences; feeding data from pandas/numpy or a generator without materializing; callers catching TypeError and missing this ValueError.","solutions":["Materialize to a list before calling: is_arithmetic_series(list(series)).","If input may be a string of numbers, parse it first (e.g. [int(x) for x in s.split()]).","Catch ValueError, not TypeError, for this function's guards."],"exampleFix":"# before\nis_arithmetic_series(data)  # ValueError when data is a tuple or range\n\n# after\nis_arithmetic_series(list(data))","handlingStrategy":"type-guard","validationCode":"series = list(series) if not isinstance(series, list) else series\nif not series:\n    raise ValueError('empty series')\nis_arithmetic_series(series)","typeGuard":"def is_series_input(v) -> bool:\n    return isinstance(v, list) and len(v) > 0","tryCatchPattern":"try:\n    is_arithmetic_series(s)\nexcept ValueError as exc:\n    if 'not valid' in str(exc):\n        s = list(s)\n    else:\n        raise","preventionTips":["Only lists pass — convert tuples, ranges, generators with list().","These guards raise ValueError, not TypeError.","Reuse one normalize_input() helper across the series module."],"tags":["python","value-error","input-validation","series","maths"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}