{"record":{"id":"a5a4deed53c148e2","repo":"apache/beam","slug":"melt-ignore-index-true-is-order-sensitive-because-it","errorCode":null,"errorMessage":"melt(ignore_index=True) is order sensitive because it requires generating a new index based on the order of the data.","messagePattern":"melt\\(ignore_index=True\\) is order sensitive because it requires generating a new index based on the order of the data\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":3998,"sourceCode":"      inplace=True,\n      base=pd.DataFrame,\n      requires_partition_by=partitionings.Index(),\n      preserves_partition_by=partitionings.Arbitrary())\n\n  values = property(frame_base.wont_implement_method(\n      pd.DataFrame, 'values', reason=\"non-deferred-result\"))\n\n  style = property(frame_base.wont_implement_method(\n      pd.DataFrame, 'style', reason=\"non-deferred-result\"))\n\n  @frame_base.with_docs_from(pd.DataFrame)\n  @frame_base.args_to_kwargs(pd.DataFrame)\n  @frame_base.populate_defaults(pd.DataFrame)\n  def melt(self, ignore_index, **kwargs):\n    \"\"\"``ignore_index=True`` is not supported, because it requires generating an\n    order-sensitive index.\"\"\"\n    if ignore_index:\n      raise frame_base.WontImplementError(\n          \"melt(ignore_index=True) is order sensitive because it requires \"\n          \"generating a new index based on the order of the data.\",\n          reason=\"order-sensitive\")\n\n    return frame_base.DeferredFrame.wrap(\n        expressions.ComputedExpression(\n            'melt',\n            lambda df: df.melt(ignore_index=False, **kwargs), [self._expr],\n            requires_partition_by=partitionings.Arbitrary(),\n            preserves_partition_by=partitionings.Singleton()))\n\n  if hasattr(pd.DataFrame, 'value_counts'):\n    @frame_base.with_docs_from(pd.DataFrame)\n    def value_counts(self, subset=None, sort=False, normalize=False,\n                     ascending=False, dropna=True):\n      \"\"\"``sort`` is ``False`` by default, and ``sort=True`` is not supported\n      because it imposes an ordering on the dataset which likely will not be\n      preserved.\"\"\"","sourceCodeStart":3980,"sourceCodeEnd":4016,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L3980-L4016","documentation":"Beam's DataFrame.melt throws WontImplementError when ignore_index=True because generating a fresh sequential index depends on the order of the data, which distributed execution does not preserve. Only ignore_index=False (keeping the original index) is supported.","triggerScenarios":"Calling df.melt() or df.melt(ignore_index=True) on a DeferredDataFrame (ignore_index defaults to True in pandas>=1.1).","commonSituations":"Unpivoting wide frames in Beam with default melt arguments; users unaware the default itself is order-sensitive.","solutions":["Pass ignore_index=False and keep the existing index.","Reset the index explicitly afterwards if a clean index is needed and order does not matter.","Drop the index column after melt if it is unused.","Fall back to local pandas for ignore_index=True semantics."],"exampleFix":"// before\nmelted = df.melt()\n// after\nmelted = df.melt(ignore_index=False)","handlingStrategy":"validation","validationCode":"def check_melt_args(ignore_index):\n    if ignore_index:\n        raise ValueError('melt(ignore_index=True) is not supported in Beam DataFrames')","typeGuard":"def melt_supported(ignore_index) -> bool:\n    return not ignore_index","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    melted = df.melt()\nexcept frame_base.WontImplementError:\n    melted = df.melt(ignore_index=False)","preventionTips":["Always pass ignore_index=False explicitly when melting in Beam.","Do not rely on a fresh sequential index from distributed reshapes.","Reset the index locally after materializing results if needed."],"tags":["pandas","apache-beam","dataframe","order-sensitive"],"backgroundTag":"invalid-argument-value","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"}