{"record":{"id":"c7069d0d99b3cef9","repo":"apache/beam","slug":"unstack-is-not-supported-when-using-pandas-1-2-0-please","errorCode":null,"errorMessage":"unstack() is not supported when using pandas < 1.2.0\nPlease upgrade to pandas 1.2.0 or higher to use this operation.","messagePattern":"unstack\\(\\) is not supported when using pandas < 1\\.2\\.0\nPlease upgrade to pandas 1\\.2\\.0 or higher to use this operation\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":986,"sourceCode":"      def truncate(df):\n        return df.truncate(before=before, after=after, axis=axis)\n\n    return frame_base.DeferredFrame.wrap(\n        expressions.ComputedExpression(\n            'truncate',\n            truncate, [self._expr],\n            requires_partition_by=partitionings.Arbitrary(),\n            preserves_partition_by=partitionings.Arbitrary()))\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 unstack(self, **kwargs):\n    level = kwargs.get('level', -1)\n\n    if self._expr.proxy().index.nlevels == 1:\n      if PD_VERSION < (1, 2):\n        raise frame_base.WontImplementError(\n            \"unstack() is not supported when using pandas < 1.2.0\\n\"\n            \"Please upgrade to pandas 1.2.0 or higher to use this operation.\")\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              'unstack', lambda s: s.unstack(**kwargs), [self._expr],\n              requires_partition_by=partitionings.Index()))\n    else:\n      # Unstacking MultiIndex objects\n      idx = self._expr.proxy().index\n\n      # Converting level (int, str, or combination) to a list of number levels\n      level_list = level if isinstance(level, list) else [level]\n      level_number_list = [idx._get_level_number(l) for l in level_list]\n\n      # Checking if levels provided are of CategoricalDtype\n      if not all(isinstance(idx.levels[l].dtype, (pd.CategoricalDtype,\n                                                  pd.BooleanDtype))\n                 for l in level_number_list):","sourceCodeStart":968,"sourceCodeEnd":1004,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L968-L1004","documentation":"DeferredFrame.unstack on a single-level index requires pandas >= 1.2.0. Older pandas' unstack behavior cannot be safely proxied by Beam's deferred expression machinery, so the wrapper hard-fails with a WontImplementError telling you to upgrade pandas.","triggerScenarios":"Calling unstack() on a DeferredSeries or DeferredDataFrame whose index has nlevels == 1 while the installed pandas version is below 1.2.0.","commonSituations":"Environments pinned to old pandas (e.g. Python 3.6-era requirements.txt); Beam deployments resolving an older pandas than the developer's local machine.","solutions":["Upgrade pandas: pip install -U 'pandas>=1.2.0' (check apache-beam's pandas compatibility range).","Pin pandas>=1.2.0 in requirements.txt so runtime matches development.","As a workaround on old pandas, move the unstack outside the pipeline (unstack after to_pandas())."],"exampleFix":"# before\npandas==1.1.5\n# after\npandas>=1.2.0","handlingStrategy":"validation","validationCode":"import pandas as pd\nif tuple(int(p) for p in pd.__version__.split('.')[:2]) < (1, 2):\n    raise RuntimeError(\"pandas >= 1.2.0 required for Beam DataFrame unstack()\")","typeGuard":null,"tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    out = s.unstack()\nexcept frame_base.WontImplementError:\n    out = s.to_pandas().unstack()","preventionTips":["Pin pandas>=1.2.0 in requirements.txt for Beam DataFrame pipelines.","Verify the runtime worker image's pandas version, not just the dev machine's.","Check the Beam release notes for the supported pandas range."],"tags":["apache-beam","dataframe","pandas","version-constraint"],"backgroundTag":"pandas-version-constraint","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"}