{"record":{"id":"229b89354680ee78","repo":"apache/beam","slug":"invalid-value-for-yield-elements-argument-s-allowed-values","errorCode":null,"errorMessage":"Invalid value for yield_elements argument, '%s'. Allowed values are 'pandas' and 'schemas'","messagePattern":"Invalid value for yield_elements argument, '(.+?)'\\. Allowed values are 'pandas' and 'schemas'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/convert.py","lineNumber":211,"sourceCode":"        conversion transform.\n    always_return_tuple: (optional, default: False) If true, always return\n        a tuple of PCollections, even if there's only one output.\n    yield_elements: (optional, default: \"schemas\") If set to \"pandas\", return\n        PCollections containing the raw Pandas objects (DataFrames or Series),\n        if set to \"schemas\", return an element-wise PCollection, where DataFrame\n        and Series instances are expanded to one element per row. DataFrames are\n        converted to schema-aware PCollections, where column values can be\n        accessed by attribute.\n    include_indexes: (optional, default: False) When yield_elements=\"schemas\",\n        if include_indexes=True, attempt to include index columns in the output\n        schema for expanded DataFrames. Raises an error if any of the index\n        levels are unnamed (name=None), or if any of the names are not unique\n        among all column and index names.\n    pipeline: (optional, unless non-deferred dataframes are passed) Used when\n        creating a PCollection from a non-deferred dataframe.\n  \"\"\"\n  if not yield_elements in (\"pandas\", \"schemas\"):\n    raise ValueError(\n        \"Invalid value for yield_elements argument, '%s'. \"\n        \"Allowed values are 'pandas' and 'schemas'\" % yield_elements)\n  if label is None:\n    # Attempt to come up with a reasonable, stable label by retrieving the name\n    # of these variables in the calling context.\n    label = 'ToPCollection(%s)' % ', '.join(_var_name(e, 3) for e in dataframes)\n\n  # Support for non-deferred dataframes.\n  deferred_dataframes = []\n  for ix, df in enumerate(dataframes):\n    if isinstance(df, frame_base.DeferredBase):\n      # TODO(robertwb): Maybe extract pipeline object?\n      deferred_dataframes.append(df)\n    elif isinstance(df, (pd.Series, pd.DataFrame)):\n      if pipeline is None:\n        raise ValueError(\n            'Pipeline keyword required for non-deferred dataframe conversion.')\n      deferred = pipeline | '%s_Defer%s' % (label, ix) >> beam.Create([df])","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/convert.py#L193-L229","documentation":"convert.to_pcollection accepts yield_elements only as 'pandas' (yield deferred pandas objects) or 'schemas' (yield Beam schema rows). Any other string raises ValueError listing the allowed values. This is a straightforward argument validation to fail fast on typos like 'schema'.","triggerScenarios":"Calling convert.to_pcollection(df, yield_elements='schema') (singular typo), yield_elements=True/None, or programmatic strings from config that aren't exactly 'pandas' or 'schemas'.","commonSituations":"Typo in the enum string; config-driven pipelines passing user-supplied values unvalidated; older code written against an internal variant of the API.","solutions":["Use exactly yield_elements='pandas' or 'schemas'.","Validate/normalize config values against the allowed set before calling.","Search code for other spellings ('schema', 'rows') and correct them.","Add an upstream enum/choices check in your config layer."],"exampleFix":"// before\nturned = convert.to_pcollection(df, yield_elements='schema')\n// after\nturned = convert.to_pcollection(df, yield_elements='schemas')","handlingStrategy":"validation","validationCode":"ALLOWED = ('pandas', 'schemas')\nif yield_elements not in ALLOWED:\n    raise ValueError(f\"yield_elements must be one of {ALLOWED}, got {yield_elements!r}\")","typeGuard":null,"tryCatchPattern":"try:\n    out = convert.to_pcollection(df, yield_elements=mode)\nexcept ValueError as e:\n    if 'Invalid value for yield_elements' in str(e):\n        mode = {'schema': 'schemas', 'rows': 'schemas'}.get(mode, 'schemas')\n        out = convert.to_pcollection(df, yield_elements=mode)\n    else:\n        raise","preventionTips":["Define yield_elements as an Enum/Literal in your config layer.","Watch for singular/plural typos ('schema' vs 'schemas').","Add a choices check where values come from user input.","Use keyword arguments explicitly at call sites."],"tags":["python","dataframe","invalid-argument","enum"],"backgroundTag":"invalid-enum-value","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"}