{"record":{"id":"0b3fbf2db5f8624b","repo":"OpenBB-finance/OpenBB","slug":"no-data-to-plot-0b3fbf","errorCode":null,"errorMessage":"No data to plot.","messagePattern":"No data to plot\\.","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"warning","filePath":"openbb_platform/providers/imf/openbb_imf/views/port_info.py","lineNumber":29,"sourceCode":"    from pandas import DataFrame\n\n    try:\n        import plotly.express as px\n        from openbb_charting.core.openbb_figure import OpenBBFigure\n    except Exception as e:\n        raise OpenBBError(\n            \"Could not import Charting modules. Install with `pip install openbb-charting`.\"\n            + f\" -> {e}\"\n        ) from e\n\n    if (\n        data is not None\n        and not isinstance(data, list)\n        or not all(isinstance(item, ImfPortInfoData) for item in data)\n    ):\n        raise OpenBBError(\"Invalid data format. Expected a list of ImfPortInfoData.\")\n    if len(data) == 0:\n        raise OpenBBError(\"No data to plot.\")\n\n    df = DataFrame([item.model_dump() for item in data]).query(\"vessel_count_total > 0\")\n\n    min_size, max_size = 4, 10\n\n    if \"country\" in df.columns and df[\"country\"].nunique() == 1:\n        share_import = df[\"share_country_maritime_import\"].fillna(0)\n        share_export = df[\"share_country_maritime_export\"].fillna(0)\n        df[\"import_export_share\"] = share_import + share_export\n        share_values = df[\"import_export_share\"]\n\n        if share_values.nunique() > 1:\n            df[\"marker_size\"] = (\n                (share_values - share_values.min())\n                / (share_values.max() - share_values.min() + 1e-9)\n            ) * (max_size - min_size) + min_size\n        else:\n            df[\"marker_size\"] = (min_size + max_size) / 2","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/views/port_info.py#L11-L47","documentation":"Emptiness check in the port-info map view: the chart cannot be built from an empty input list, so it raises before constructing the DataFrame (which would additionally be filtered by vessel_count_total > 0). It signals the caller passed zero rows, usually an upstream fetch that matched nothing.","triggerScenarios":"Calling plot_port_info_map([]) after a port-info fetch returned no records - e.g. a country filter with no ports, or a period with no vessel observations. Note that even non-empty input whose rows all have vessel_count_total == 0 yields an empty DataFrame after .query(...), producing an empty map rather than this error.","commonSituations":"Filters (country, date) excluding all ports; API downtime upstream causing empty results that a wrapper converted to []; pagination bugs returning zero pages.","solutions":["Verify the fetch call's filters and retry the data fetch before plotting.","Handle EmptyDataError from the data endpoint instead of forwarding an empty list to the view.","If all rows have vessel_count_total == 0, expect an empty figure - filter or message accordingly in your UI."],"exampleFix":"# before\nresults = obb.economy.imf.port_info(country='XX', chart=True)\n# after\nres = obb.economy.imf.port_info(country='XX')\nif not res.results:\n    raise SystemExit(f'No ports found for {res.provider} - adjust filters')\nchart = res.charting.to_chart()","handlingStrategy":"validation","validationCode":"if not data:\n    print('No port data for the given filters')\nelse:\n    plot_port_info_map(data)","typeGuard":"def has_rows(data: list | None) -> bool:\n    return bool(data)","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    plot_port_info_map(data)\nexcept OpenBBError as e:\n    if str(e) == 'No data to plot.':\n        show_empty_state()\n    else:\n        raise","preventionTips":["Guard emptiness before charting","Also handle the vessel_count_total>0 post-filter case (empty map, not error)","Catch upstream EmptyDataError instead of forwarding []"],"tags":["imf","empty-data","charting","openbberror"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}