@@ -185,7 +185,19 @@ def produces_keys(self) -> bool:
185185 return self ._produces_keys
186186
187187 def __getitem__ (self , idx : tuple [int , ...]) -> Any :
188- return self .mapping [idx ]
188+ try :
189+ return self .mapping [idx ]
190+ except KeyError as err :
191+ # If a DataFrame collection was converted
192+ # to an Array collection, the dimesion of
193+ # `idx` may not agree with the keys in
194+ # `self.mapping`. In this case, we can
195+ # use `self.numblocks` to check for a key
196+ # match in the leading elements of `idx`
197+ flat_idx = idx [: len (self .numblocks )]
198+ if flat_idx in self .mapping :
199+ return self .mapping [flat_idx ]
200+ raise err
189201
190202 def __dask_distributed_pack__ (
191203 self , required_indices : tuple | list [tuple [int , ...]] | None = None
@@ -204,7 +216,7 @@ def __dask_distributed_pack__(
204216 },
205217 "numblocks" : self .numblocks ,
206218 "produces_tasks" : self .produces_tasks ,
207- "produces_keys" : self ._produces_keys ,
219+ "produces_keys" : self .produces_keys ,
208220 }
209221
210222 @classmethod
0 commit comments