{"record":{"id":"1b077fb080f6b11c","repo":"TheAlgorithms/Python","slug":"input-list-must-be-a-non-empty-list","errorCode":null,"errorMessage":"Input list must be a non empty list","messagePattern":"Input list must be a non empty list","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/series/arithmetic.py","lineNumber":32,"sourceCode":"    >>> 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])\n    7.5\n    >>> arithmetic_mean(4)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/series/arithmetic.py#L14-L50","documentation":"is_arithmetic_series() in maths/series/arithmetic.py raises ValueError('Input list must be a non empty list') when it receives an actual list of length 0. The check runs after the isinstance-list guard, so this error specifically means 'correct type, no elements'. A one-element list is legal and returns True (vacuously a series); the empty list has no differences to compare, so it is treated as invalid input rather than vacuously True.","triggerScenarios":"Calling is_arithmetic_series([]), or passing a list built from filtering/slicing that legitimately ended up empty (e.g. [x for x in data if x > 0] with no matches).","commonSituations":"Batch-processing pipelines where some windows/batches are empty; splitting text or data into chunks and processing each; tests that assume empty input returns False or True rather than raising.","solutions":["Skip the call when the list is empty: if series: ... else handle the no-data case explicitly.","Default empty inputs upstream (e.g. treat as False) if your domain defines empty as 'not a series'.","Catch ValueError if emptiness is an expected runtime condition you want to absorb."],"exampleFix":"# before\nis_arithmetic_series(window)  # ValueError when window == []\n\n# after\nresult = is_arithmetic_series(window) if window else False","handlingStrategy":"validation","validationCode":"if not series:\n    result = False  # or skip; define your empty-window policy\nelse:\n    result = is_arithmetic_series(series)","typeGuard":"def is_non_empty_list(v) -> bool:\n    return isinstance(v, list) and len(v) > 0","tryCatchPattern":"try:\n    is_arithmetic_series(s)\nexcept ValueError as exc:\n    if 'non empty' in str(exc):\n        s_is_series = False  # empty input policy\n    else:\n        raise","preventionTips":["Skip or default empty windows/batches before calling.","Filtering can silently produce [] — check results of comprehensions.","Single-element lists return True; only [] raises."],"tags":["python","value-error","empty-list","series","maths"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}