{"record":{"id":"8977681b02ea9828","repo":"apache/beam","slug":"not-dataframes-or-series","errorCode":null,"errorMessage":"not dataframes or series","messagePattern":"not dataframes or series","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/io.py","lineNumber":163,"sourceCode":"      pd.read_json,\n      path,\n      args,\n      kwargs,\n      incremental=kwargs.get('lines', False),\n      splitter=_DelimSplitter(b'\\n', _DEFAULT_BYTES_CHUNKSIZE) if kwargs.get(\n          'lines', False) else None,\n      binary=False)\n\n\n@frame_base.with_docs_from(pd.DataFrame)\ndef to_json(df, path, orient=None, *args, **kwargs):\n  if orient is None:\n    if isinstance(df._expr.proxy(), pd.DataFrame):\n      orient = 'columns'\n    elif isinstance(df._expr.proxy(), pd.Series):\n      orient = 'index'\n    else:\n      raise frame_base.WontImplementError('not dataframes or series')\n  kwargs['orient'] = orient\n  return _as_pc(df) | _WriteToPandas(\n      'to_json',\n      path,\n      args,\n      kwargs,\n      incremental=orient in ('index', 'records', 'values'),\n      binary=False)\n\n\n@frame_base.with_docs_from(pd)\ndef read_html(path, *args, **kwargs):\n  return _ReadFromPandas(\n      lambda *args, **kwargs: pd.read_html(*args, **kwargs)[0],\n      path,\n      args,\n      kwargs)\n","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/io.py#L145-L181","documentation":"apache_beam.dataframe.io.to_json only supports deferring a pd.DataFrame or pd.Series to JSON via the Beam pipeline. When the orient argument is not supplied, it inspects the object's proxy type; if the expression wraps neither a DataFrame nor a Series, it raises WontImplementError because there is no defined 'orient' for such an object and no deferred implementation exists.","triggerScenarios":"Calling beam.dataframe.io.to_json(df, path, orient=None) where df is a Beam DeferredDataFrame whose _expr.proxy() is neither a pandas DataFrame nor a pandas Series (e.g. an unexpected intermediate expression type).","commonSituations":"Passing a non-dataframe deferred expression (e.g. a scalar or grouped result) to to_json; constructing deferred frames through unusual transforms that lose the DataFrame/Series proxy; forgetting that Beam's dataframe API implements only a pandas subset.","solutions":["Pass an explicit orient='columns' (DataFrame) or orient='index' (Series) argument to to_json.","Ensure the argument is a real deferred DataFrame or Series from beam.dataframe.io read_* calls.","Convert via .to_frame() / .to_series() so the proxy type is a pd.DataFrame or pd.Series.","If the object genuinely is neither, write it out with a plain Beam PTransform (e.g. Map + WriteToText) instead of to_json."],"exampleFix":"// before\ndefer.to_json(result, 'out.json')  # result is neither DataFrame nor Series\n// after\ndefer.to_json(result.to_frame(), 'out.json')  # or orient='index' for a Series","handlingStrategy":"type-guard","validationCode":"proxy = df._expr.proxy()\nif not isinstance(proxy, (pd.DataFrame, pd.Series)):\n    raise TypeError('to_json requires a deferred DataFrame or Series')","typeGuard":"def is_deferred_frame_or_series(df):\n    return isinstance(df._expr.proxy(), (pd.DataFrame, pd.Series))","tryCatchPattern":"try:\n    beam_df.io.to_json(df, path)\nexcept frame_base.WontImplementError:\n    df = df.to_frame()\n    beam_df.io.to_json(df, path)","preventionTips":["Check proxy type before deferred io calls","Pass explicit orient when the frame type is ambiguous","Use only documented read_* entry points to create deferred frames"],"tags":["apache-beam","pandas","dataframe","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}