{"record":{"id":"7c9965ab3a410c00","repo":"apache/beam","slug":"type-row-index","errorCode":null,"errorMessage":"type(row_index)","messagePattern":"type\\(row_index\\)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":4954,"sourceCode":"        reindexed_expr = expressions.ComputedExpression(\n            'data_to_index',\n            data_to_index,\n            [key._expr],\n            requires_partition_by=partitionings.Arbitrary(),\n            preserves_partition_by=partitionings.Singleton(),\n        )\n        args = [self._frame._expr, reindexed_expr]\n    elif callable(key):\n\n      def checked_callable_key(df):\n        computed_index = key(df)\n        if isinstance(computed_index, tuple):\n          row_index, _ = computed_index\n        else:\n          row_index = computed_index\n        if isinstance(row_index, list) and row_index and isinstance(\n            row_index[0], bool):\n          raise NotImplementedError(type(row_index))\n        elif not isinstance(row_index, (slice, pd.Series)):\n          raise NotImplementedError(type(row_index))\n        return computed_index\n\n      args = [self._frame._expr]\n      func = lambda df: df.loc[checked_callable_key]\n    else:\n      raise NotImplementedError(type(key))\n\n    return frame_base.DeferredFrame.wrap(\n        expressions.ComputedExpression(\n            'loc',\n            func,\n            args,\n            requires_partition_by=(\n                partitionings.JoinIndex()\n                if len(args) > 1\n                else partitionings.Arbitrary()),","sourceCodeStart":4936,"sourceCodeEnd":4972,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L4936-L4972","documentation":"When the .loc key is callable, Beam invokes it during pipeline construction with an empty proxy to compute the index; if the callable returns a list of booleans, NotImplementedError(type(row_index)) is raised because boolean-list row selection is unsupported.","triggerScenarios":"df.loc[lambda df: [bool(x) for x in ...]] — a callable key returning a Python bool list on a Beam deferred DataFrame.","commonSituations":"Callable-based pandas idiom migrated to Beam where the lambda builds a list instead of a Series; computing masks in plain Python rather than with dataframe ops.","solutions":["Make the callable return a pandas Series of booleans indexed like the frame, not a list.","Compute the mask with deferred expressions: df.loc[lambda df: df['v'] > 0].","Validate the callable's return type at construction time against (slice, pd.Series) before passing it."],"exampleFix":"# before\ndf.loc[lambda df: [v > 0 for v in df['v']]]\n# after\ndf.loc[lambda df: df['v'] > 0]","handlingStrategy":"type-guard","validationCode":"result = key_fn(empty_proxy_df)\nassert isinstance(result, (slice, pd.Series)), 'callable .loc key must return slice or Series, got %r' % type(result)","typeGuard":"def returns_valid_loc_index(fn, proxy_df) -> bool:\n    import pandas as pd\n    out = fn(proxy_df)\n    return isinstance(out, (slice, pd.Series)) and not (isinstance(out, list))","tryCatchPattern":"try:\n    out = beam_df.loc[key_fn]\nexcept NotImplementedError as e:\n    if str(e) == str(type(row_index)):\n        out = beam_df.loc[lambda df: pd.Series(key_fn(df), index=df.index)]","preventionTips":["Callable .loc keys must return slices or boolean pandas Series.","Exercise callable keys against an empty proxy at construction time.","Avoid Python-level list comprehensions in masks; use dataframe expressions."],"tags":["apache-beam","dataframe","not-implemented","callable-key"],"backgroundTag":"unsupported-operation","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"}