File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -260,11 +260,16 @@ class Index {
260
260
if (!ids_.is_none ()) {
261
261
py::array_t < size_t , py::array::c_style | py::array::forcecast > items (ids_);
262
262
auto ids_numpy = items.request ();
263
- std::vector<size_t > ids1 (ids_numpy.shape [0 ]);
264
- for (size_t i = 0 ; i < ids1.size (); i++) {
265
- ids1[i] = items.data ()[i];
263
+
264
+ if (ids_numpy.ndim == 0 ) {
265
+ throw std::invalid_argument (" get_items accepts a list of indices and returns a list of vectors" );
266
+ } else {
267
+ std::vector<size_t > ids1 (ids_numpy.shape [0 ]);
268
+ for (size_t i = 0 ; i < ids1.size (); i++) {
269
+ ids1[i] = items.data ()[i];
270
+ }
271
+ ids.swap (ids1);
266
272
}
267
- ids.swap (ids1);
268
273
}
269
274
270
275
std::vector<std::vector<data_t >> data;
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ def testGettingItems(self):
41
41
print ("Adding all elements (%d)" % (len (data )))
42
42
p .add_items (data , labels )
43
43
44
+ # Getting data by label should raise an exception if a scalar is passed:
45
+ self .assertRaises (ValueError , lambda : p .get_items (labels [0 ]))
46
+
44
47
# After adding them, all labels should be retrievable
45
48
returned_items = p .get_items (labels )
46
49
self .assertSequenceEqual (data .tolist (), returned_items )
You can’t perform that action at this time.
0 commit comments