{"record":{"id":"703168e88c43a083","repo":"OpenBB-finance/OpenBB","slug":"error-e-703168","errorCode":null,"errorMessage":"Error: {e}","messagePattern":"Error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/obbject_extensions/charting/openbb_charting/charts/generic_charts.py","lineNumber":572,"sourceCode":"    except Exception as _:\n        figure = OpenBBFigure(create_backend=True)\n\n    figure = figure.create_subplots(\n        1,\n        1,\n        shared_xaxes=False,\n        vertical_spacing=0.06,\n        horizontal_spacing=0.01,\n        row_width=[1],\n        specs=[[{\"secondary_y\": True}]],\n    )\n\n    try:\n        data = Series(data=values, index=keys)\n        increasing_data = data[data > 0]  # type: ignore\n        decreasing_data = data[data < 0]  # type: ignore\n    except Exception as e:\n        raise ValueError(f\"Error: {e}\") from e\n\n    if not increasing_data.empty:  # type: ignore\n        figure.add_bar(\n            x=increasing_data.index if orientation == \"v\" else increasing_data,  # type: ignore\n            y=increasing_data if orientation == \"v\" else increasing_data.index,  # type: ignore\n            marker=dict(color=colors[0]),\n            orientation=orientation,\n            showlegend=False,\n            width=0.95 / len(keys) * 0.75 if barmode == \"group\" else 0.95,\n            hoverinfo=\"y\" if orientation == \"v\" else \"x\",\n        )\n    if not decreasing_data.empty:  # type: ignore\n        figure.add_bar(\n            x=decreasing_data.index if orientation == \"v\" else decreasing_data,  # type: ignore\n            y=decreasing_data if orientation == \"v\" else decreasing_data.index,  # type: ignore\n            marker=dict(color=colors[1]),\n            orientation=orientation,\n            showlegend=False,","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/obbject_extensions/charting/openbb_charting/charts/generic_charts.py#L554-L590","documentation":"In the bar chart builder (generic_charts.py), the incoming values are packed into a pandas Series indexed by keys; if that construction fails - length mismatch between keys and values, unhashable/NaN keys, or non-iterable input - the exception is wrapped as ValueError('Error: {e}') with the original message preserved.","triggerScenarios":"Calling the bar chart function with len(keys) != len(values); keys containing NaN or unhashable types; values as a scalar instead of a sequence; dicts/iterables of inconsistent length.","commonSituations":"Building category charts from aggregated provider data where a filter dropped some rows but keys were computed beforehand; passing zip results of unequal lists; None values sneaking into keys.","solutions":["Verify lengths match: assert len(keys) == len(values)","Sanitize keys (drop NaN, convert to str) and values (coerce to float) before calling","Read the embedded message after 'Error:' - it is pandas' own Series construction error telling you the exact mismatch"],"exampleFix":"# before\nfig = create_bar_chart(values=[1, 2, 3], keys=['a', 'b'])\n\n# after\nassert len(keys) == len(values)\nfig = create_bar_chart(values=values, keys=keys)","handlingStrategy":"validation","validationCode":"assert len(keys) == len(values), f'keys/values length mismatch: {len(keys)} vs {len(values)}'\nkeys = [str(k) for k in keys]\nvalues = [float(v) for v in values]","typeGuard":"def is_paired_series(keys, values) -> bool:\n    try:\n        return len(keys) == len(values) and all(isinstance(k, (str, int, float)) for k in keys)\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    fig = create_bar_chart(values=values, keys=keys)\nexcept ValueError as e:\n    if str(e).startswith('Error:'):\n        logging.error('bar chart data invalid: %s', str(e))","preventionTips":["Always assert equal lengths for keys and values","Stringify keys to avoid NaN/unhashable index errors","Coerce values to float before charting"],"tags":["openbb","charting","bar-chart","length-mismatch"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}