{"record":{"id":"a1e88c7d3964a508","repo":"TheAlgorithms/Python","slug":"input-series-is-not-valid-valid-series-2-4-8","errorCode":null,"errorMessage":"Input series is not valid, valid series - [2, 4, 8]","messagePattern":"Input series is not valid, valid series - \\[2, 4, 8\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/series/geometric.py","lineNumber":31,"sourceCode":"    >>> is_geometric_series([2, 4, 8])\n    True\n    >>> 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","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/series/geometric.py#L13-L49","documentation":"is_geometric_series() in maths/series/geometric.py checks whether consecutive ratios series[i+1]/series[i] are constant. Its first guard requires isinstance(series, list); anything else — int, string, tuple, generator — raises ValueError('Input series is not valid, valid series - [2, 4, 8]') (the example uses the geometric 2,4,8, unlike the arithmetic sibling's 2,4,6). The check precedes the empty-list check, so a non-list empty-ish input (e.g. '') raises this error, not the non-empty one.","triggerScenarios":"Calling is_geometric_series(4), is_geometric_series((2, 4, 8)), or passing a range/iterator without materializing. Strings like '248' also land here.","commonSituations":"Passing tuples from DB rows or unpacking, ranges, or numpy arrays; generic sequence-checking code shared across the arithmetic/geometric modules where only list is accepted; catching TypeError and missing the ValueError.","solutions":["Materialize to list: is_geometric_series(list(series)).","Parse numeric strings into int lists before calling.","Catch ValueError per the module's convention for all input guards."],"exampleFix":"# before\nis_geometric_series(seq)  # ValueError when seq is a tuple or range\n\n# after\nis_geometric_series(list(seq))","handlingStrategy":"type-guard","validationCode":"series = list(series) if not isinstance(series, list) else series\nif not series:\n    raise ValueError('empty series')\nis_geometric_series(series)","typeGuard":"def is_series_input(v) -> bool:\n    return isinstance(v, list) and len(v) > 0","tryCatchPattern":"try:\n    is_geometric_series(s)\nexcept ValueError as exc:\n    if 'not valid' in str(exc):\n        s = list(s)\n    else:\n        raise","preventionTips":["Only lists are accepted; materialize tuples/ranges/generators first.","Note the geometric example message ([2, 4, 8]) differs from the arithmetic one ([2, 4, 6]).","Normalize inputs once in a shared wrapper for 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-15T17:31:12.345Z"}