{"record":{"id":"9bb51af5eaf384b6","repo":"alibaba/DataX","slug":"tabular-data-doesn-t-appear-to-be-a-dict-or-a-data","errorCode":null,"errorMessage":"tabular data doesn't appear to be a dict or a DataFrame","messagePattern":"tabular data doesn't appear to be a dict or a DataFrame","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"otsstreamreader/tools/tabulate.py","lineNumber":699,"sourceCode":"        is_headers2bool_broken = True\n        headers = list(headers)\n\n    index = None\n    if hasattr(tabular_data, \"keys\") and hasattr(tabular_data, \"values\"):\n        # dict-like and pandas.DataFrame?\n        if hasattr(tabular_data.values, \"__call__\"):\n            # likely a conventional dict\n            keys = tabular_data.keys()\n            rows = list(izip_longest(*tabular_data.values()))  # columns have to be transposed\n        elif hasattr(tabular_data, \"index\"):\n            # values is a property, has .index => it's likely a pandas.DataFrame (pandas 0.11.0)\n            keys = tabular_data.keys()\n            vals = tabular_data.values  # values matrix doesn't need to be transposed\n            # for DataFrames add an index per default\n            index = list(tabular_data.index)\n            rows = [list(row) for row in vals]\n        else:\n            raise ValueError(\"tabular data doesn't appear to be a dict or a DataFrame\")\n\n        if headers == \"keys\":\n            headers = list(map(_text_type,keys))  # headers should be strings\n\n    else:  # it's a usual an iterable of iterables, or a NumPy array\n        rows = list(tabular_data)\n\n        if (headers == \"keys\" and\n            hasattr(tabular_data, \"dtype\") and\n            getattr(tabular_data.dtype, \"names\")):\n            # numpy record array\n            headers = tabular_data.dtype.names\n        elif (headers == \"keys\"\n              and len(rows) > 0\n              and isinstance(rows[0], tuple)\n              and hasattr(rows[0], \"_fields\")):\n            # namedtuple\n            headers = list(map(_text_type, rows[0]._fields))","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/otsstreamreader/tools/tabulate.py#L681-L717","documentation":"ValueError from tabulate._format: the input has a keys()/values() shape (treated as dict-like) but neither callable .values() nor a usable .index attribute, so this old (0.7.x-era) tabulate cannot recognize it as a dict or a pandas DataFrame. It is a duck-typing heuristic failure against newer/custom mapping or DataFrame-like types.","triggerScenarios":"Passing a mapping-like object (has keys but .values is a property, e.g. modern pandas DataFrame normally has .index so fails earlier heuristics; or OrderedDict subclasses, or dict-like ORM results) that matches neither the 0.11-era DataFrame fingerprint nor a plain dict.","commonSituations":"Vendored old tabulate used with modern pandas/numpy versions whose APIs moved; passing dict_items, generators, or custom Mapping objects to the otsstreamreader tooling.","solutions":["Convert before calling: pass list(df.itertuples(index=False)) or [list(r) for r in df.values].","Pass a plain dict {col: list_of_values} which the heuristic supports.","Upgrade/replace the vendored tabulate with a current release that handles modern pandas."],"exampleFix":"# before\ntabulate(df, headers='keys')\n# after\ntabulate([list(r) for r in df.itertuples(index=False)], headers=list(df.columns))","handlingStrategy":"type-guard","validationCode":"if hasattr(tabular_data, 'keys') and not isinstance(tabular_data, dict):\n    tabular_data = list(tabular_data.values())  # or convert DataFrame rows explicitly","typeGuard":"def is_supported_mapping(o):\n    return isinstance(o, dict) or (hasattr(o, 'values') and callable(o.values)) or hasattr(o, 'index')","tryCatchPattern":null,"preventionTips":["Normalize exotic inputs to list-of-lists or plain dict before calling this vendored tabulate.","Keep the vendored tabulate version pinned and tested against your pandas version."],"tags":["python","tabulate","pandas","duck-typing","dev-tools"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}