{"record":{"id":"149f310e7ad09702","repo":"apache/beam","slug":"proxy-proxy-has-unsupported-type-type-proxy-schemas","errorCode":null,"errorMessage":"Proxy '{proxy}' has unsupported type '{type(proxy)}'","messagePattern":"Proxy '(.+?)' has unsupported type '(.+?)'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/schemas.py","lineNumber":130,"sourceCode":"  PCollection.\n  \"\"\"\n  return element_typehint_from_dataframe_proxy(proxy, include_indexes).user_type\n\n\ndef _element_typehint_from_proxy(\n    proxy: pd.core.generic.NDFrame, include_indexes: bool = False):\n  if isinstance(proxy, pd.DataFrame):\n    return element_typehint_from_dataframe_proxy(\n        proxy, include_indexes=include_indexes)\n  elif isinstance(proxy, pd.Series):\n    if include_indexes:\n      warnings.warn(\n          \"include_indexes=True for a Series input. Note that this \"\n          \"parameter is _not_ respected for DeferredSeries \"\n          \"conversion.\")\n    return dtype_to_fieldtype(proxy.dtype)\n  else:\n    raise TypeError(f\"Proxy '{proxy}' has unsupported type '{type(proxy)}'\")\n\n\ndef element_typehint_from_dataframe_proxy(\n    proxy: pd.DataFrame, include_indexes: bool = False) -> RowTypeConstraint:\n\n  output_columns = []\n  if include_indexes:\n    remaining_index_names = list(proxy.index.names)\n    i = 0\n    while len(remaining_index_names):\n      index_name = remaining_index_names.pop(0)\n      if index_name is None:\n        raise ValueError(\n            \"Encountered an unnamed index. Cannot convert to a \"\n            \"schema-aware PCollection with include_indexes=True. \"\n            \"Please name all indexes or consider not including \"\n            \"indexes.\")\n      elif index_name in remaining_index_names:","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/schemas.py#L112-L148","documentation":"_element_typehint_from_proxy converts a proxy (a small pandas Series/DataFrame/Index standing in for a batch) into a Beam type hint. If the proxy is neither a Series (with .dtype) nor a recognized index type, it raises TypeError since no element type can be derived.","triggerScenarios":"Returning or producing, from a Beam DataFrame transform, a proxy object that is not a DataFrame/Series/Index — e.g. a scalar, dict, or custom object; incorrect return type from a dofn/apply over dataframes.","commonSituations":"Custom transforms in beam.dataframe.apply that accidentally return a plain value or a non-pandas object instead of a DataFrame/Series; version differences changing proxy wrapper classes.","solutions":["Ensure the transform returns a pandas DataFrame or Series (the proxy type must be one of these)","Wrap scalar results in a single-row/one-column DataFrame or Series before returning","Check the transform's return type annotation matches the actual proxy type produced","Inspect the proxy at type(proxy) printed in the message to find what object leaked through"],"exampleFix":"// before\ndef fn(df):\n  return df['a'].sum()  # scalar proxy -> TypeError\n// after\ndef fn(df):\n  return df[['a']].sum()  # DataFrame proxy","handlingStrategy":"type-guard","validationCode":"import pandas as pd\nif not isinstance(proxy, (pd.DataFrame, pd.Series, pd.Index)):\n    raise TypeError(f'Transform proxy must be DataFrame/Series/Index, got {type(proxy)!r}')","typeGuard":"import pandas as pd\ndef is_valid_proxy(proxy) -> bool:\n    return isinstance(proxy, (pd.DataFrame, pd.Series, pd.Index))","tryCatchPattern":"try:\n    output_type = schemas.element_typehint_from_dataframe_proxy(proxy)\nexcept TypeError as e:\n    raise TypeError(f'Bad proxy {type(proxy)!r}: wrap scalars in a DataFrame/Series') from e","preventionTips":["Ensure Beam DataFrame transforms return DataFrame/Series, never scalars or dicts","Add return-type sanity checks in custom apply transforms","Test proxy construction in unit tests before running pipelines"],"tags":["python","apache-beam","dataframe","type-hint","type-error"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}