{"record":{"id":"9f2e6864e9bcee5d","repo":"apache/beam","slug":"type-key","errorCode":null,"errorMessage":"type(key)","messagePattern":"type\\(key\\)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":4916,"sourceCode":"  def nlevels(self):\n    return self._frame._expr.proxy().index.nlevels\n\n  def __getattr__(self, name):\n    raise NotImplementedError('index.%s' % name)\n\n\n@populate_not_implemented(pd.core.indexing._LocIndexer)\nclass _DeferredLoc(object):\n  def __init__(self, frame):\n    self._frame = frame\n\n  def __getitem__(self, key):\n    if isinstance(key, tuple):\n      rows, cols = key\n      return self[rows][cols]\n    elif isinstance(key, list) and key and isinstance(key[0], bool):\n      # Aligned by numerical key.\n      raise NotImplementedError(type(key))\n    elif isinstance(key, list):\n      # Select rows, but behaves poorly on missing values.\n      raise NotImplementedError(type(key))\n    elif isinstance(key, slice):\n      args = [self._frame._expr]\n      func = lambda df: df.loc[key]\n    elif isinstance(key, frame_base.DeferredFrame):\n      func = lambda df, key: df.loc[key]\n      if pd.core.dtypes.common.is_bool_dtype(key._expr.proxy()):\n        # Boolean indexer, just pass it in as-is\n        args = [self._frame._expr, key._expr]\n      else:\n        # Likely a DeferredSeries of labels, overwrite the key's index with it's\n        # values so we can colocate them with the labels they're selecting\n        def data_to_index(s):\n          s = s.copy()\n          s.index = s\n          return s","sourceCodeStart":4898,"sourceCodeEnd":4934,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L4898-L4934","documentation":"In _DeferredLoc.__getitem__, a list-of-booleans key (boolean list aligned by numerical position) is not implemented, so NotImplementedError(type(key)) is raised. Beam supports tuple, plain-list-of-labels (with caveats), slices, deferred boolean Series, and callables — but not boolean lists.","triggerScenarios":"df.loc[[True, False, True, ...]] on a Beam deferred DataFrame with a plain Python list of booleans.","commonSituations":"Copying pandas masking code that built a bool list from external logic; converting a numpy bool array to list and using it as .loc key.","solutions":["Convert the boolean list to a pandas Series (or Beam deferred Series) with the correct index and use that as the key.","Use a callable key: df.loc[lambda df: pd.Series(bools, index=df.index)].","Filter with an expression producing a deferred boolean Series instead of a materialized list."],"exampleFix":"// before\ndf.loc[[True, False, True]]\n# after\ndf.loc[pd.Series([True, False, True], index=df.index)]  # or a deferred bool Series","handlingStrategy":"type-guard","validationCode":"if isinstance(key, list) and key and isinstance(key[0], bool):\n    key = pd.Series(key, index=df.index)","typeGuard":"def is_loc_safe_key(key) -> bool:\n    import pandas as pd\n    return (isinstance(key, slice) or isinstance(key, pd.Series)\n            or (isinstance(key, tuple) and all(isinstance(k, (slice, pd.Series)) for k in key)))","tryCatchPattern":"try:\n    out = beam_df.loc[key]\nexcept NotImplementedError as e:\n    if str(e) == str(type(key)):\n        out = beam_df.loc[pd.Series(list(key), index=beam_df.index)]","preventionTips":["Never pass raw bool lists to .loc on deferred frames.","Build boolean masks as pandas Series or deferred expressions.","Test .loc calls at construction time with empty proxy frames."],"tags":["apache-beam","dataframe","not-implemented","loc-indexing"],"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"}