Skip to content

Commit

Permalink
Bugfix for get_by_indices.
Browse files Browse the repository at this point in the history
  • Loading branch information
root-11 committed Jul 13, 2023
1 parent 87a607e commit 2b0ed22
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tablite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,22 @@ def get_by_indices(self, indices):
indices (np.array): targets
"""
type_check(indices, np.ndarray)
arrays = []

dtypes = set()
values = np.empty(indices.shape, dtype=object) # placeholder for the indexed values.

for start, end, data in self.iter_by_page():
range_match = np.where(((indices >= start) & (indices < end)) | (indices == -1))[0]
if len(range_match):
sub_index = np.take(indices, range_match)
arr = np.take(data, sub_index - start)
arrays.append(arr)
return np_type_unify(arrays)
dtypes.add(arr.dtype)
np.put(values, range_match, arr)

if len(dtypes) == 1: # simplify the datatype.
dtype = next(iter(dtypes))
values = np.array(values, dtype=dtype)
return values

def __iter__(self): # USER FUNCTION.
for page in self.pages:
Expand Down

0 comments on commit 2b0ed22

Please sign in to comment.