Skip to content

Commit a965255

Browse files
committed
iterate over individual rows for local dataset
1 parent f39c0d3 commit a965255

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mp_api/client/core/utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,21 @@ def num_chunks(self) -> int:
173173
return len(self._row_groups)
174174

175175
def __getitem__(self, idx):
176-
return list(
177-
map(
178-
lambda x: self._document_model(**x) if self._use_document_model else x,
179-
self._row_groups[idx].to_table().to_pylist(maps_as_pydicts="strict"),
176+
if isinstance(idx, slice):
177+
start, stop, step = idx.indices(len(self))
178+
_take = list(range(start, stop, step))
179+
ds_slice = self._dataset.take(_take).to_pylist(maps_as_pydicts="strict")
180+
return (
181+
[self._document_model(**_row) for _row in ds_slice]
182+
if self._use_document_model
183+
else ds_slice
180184
)
181-
)
185+
186+
_row = self._dataset.take([idx]).to_pylist(maps_as_pydicts="strict")[0]
187+
return self._document_model(**_row) if self._use_document_model else _row
182188

183189
def __len__(self) -> int:
184-
return self.num_chunks
190+
return self._dataset.count_rows()
185191

186192
def __iter__(self):
187193
current = self._start

0 commit comments

Comments
 (0)