{"record":{"id":"24d52a151ff4512f","repo":"TheAlgorithms/Python","slug":"input-list-must-be-a-non-empty-list-24d52a","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/geometric.py","lineNumber":33,"sourceCode":"    >>> is_geometric_series([3, 6, 12, 24])\n    True\n    >>> is_geometric_series([1, 2, 3])\n    False\n    >>> is_geometric_series([0, 0, 3])\n    False\n    >>> is_geometric_series([])\n    Traceback (most recent call last):\n        ...\n    ValueError: Input list must be a non empty list\n    >>> is_geometric_series(4)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input series is not valid, valid series - [2, 4, 8]\n    \"\"\"\n    if not isinstance(series, list):\n        raise ValueError(\"Input series is not valid, valid series - [2, 4, 8]\")\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    try:\n        common_ratio = series[1] / series[0]\n        for index in range(len(series) - 1):\n            if series[index + 1] / series[index] != common_ratio:\n                return False\n    except ZeroDivisionError:\n        return False\n    return True\n\n\ndef geometric_mean(series: list) -> float:\n    \"\"\"\n    return the geometric mean of series\n\n    >>> geometric_mean([2, 4, 8])\n    3.9999999999999996","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/series/geometric.py#L15-L51","documentation":"Raised by is_geometric_series() in maths/series/geometric.py when the input is a list but contains zero elements. The function first checks that the input is a list (non-lists get a different 'Input series is not valid' error), then rejects empty lists because a common ratio cannot be computed from no terms. It is a guard against meaningless input, not a computational failure.","triggerScenarios":"Calling is_geometric_series([]) — any empty list argument. Common when a list is built dynamically (e.g. from user input, file parsing, or a filter/slice) and ends up empty before being passed in.","commonSituations":"Passing a programmatically generated list that an upstream step emptied (empty file, filter that matched nothing, slice out of range like data[5:3]). Not triggered by non-list types or single-element lists (a one-element list returns True).","solutions":["Check the list is non-empty before calling: if series and is_geometric_series(series): ...","Fix the upstream data source so it produces at least one element","Pass a default sample list such as [2, 4, 8] when the input may be empty"],"exampleFix":"# before\nprint(is_geometric_series(my_list))\n\n# after\nif my_list:\n    print(is_geometric_series(my_list))\nelse:\n    print('no data')","handlingStrategy":"validation","validationCode":"def check_geometric_input(series):\n    return isinstance(series, list) and len(series) > 0\n\nif check_geometric_input(series):\n    print(is_geometric_series(series))","typeGuard":"def is_non_empty_number_list(series: object) -> bool:\n    return isinstance(series, list) and len(series) > 0 and all(\n        isinstance(x, (int, float)) for x in series\n    )","tryCatchPattern":"try:\n    is_geometric_series(series)\nexcept ValueError as e:\n    logger.warning('invalid series input: %s', e)","preventionTips":["Normalize data sources so lists are never empty before math calls","Add truthiness checks (if series:) at call sites","Write unit tests covering the empty-list edge case"],"tags":["python","math","validation","value-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}