4
4
from tqdm .autonotebook import tqdm
5
5
from importlib .util import find_spec
6
6
import numbers
7
+ import numpy as np
7
8
8
9
from collections .abc import Iterable , Mapping
9
10
from typing import Union , List , Tuple , Optional , Dict , Any
@@ -184,6 +185,11 @@ def _dict_to_vector(item):
184
185
f"Column `sparse_values` is expected to be a dictionary, found { type (item ['sparse_values' ])} " )
185
186
indices = item ['sparse_values' ].get ('indices' , None )
186
187
values = item ['sparse_values' ].get ('values' , None )
188
+
189
+ if isinstance (values , np .ndarray ):
190
+ values = values .tolist ()
191
+ if isinstance (indices , np .ndarray ):
192
+ indices = indices .tolist ()
187
193
try :
188
194
sparse_values = SparseValues (indices = indices , values = values )
189
195
except TypeError as e :
@@ -195,8 +201,11 @@ def _dict_to_vector(item):
195
201
if not isinstance (metadata , Mapping ):
196
202
raise TypeError (f"Column `metadata` is expected to be a dictionary, found { type (metadata )} " )
197
203
204
+ if isinstance (item ['values' ], np .ndarray ):
205
+ item ['values' ] = item ['values' ].tolist ()
206
+
198
207
try :
199
- return Vector (id = item ['id' ], values = item ['values' ], sparse_values = sparse_values , metadata = metadata )
208
+ return Vector (id = item ['id' ],values = item ['values' ], sparse_values = sparse_values , metadata = metadata )
200
209
201
210
except TypeError as e :
202
211
# if not isinstance(item['values'], Iterable) or not isinstance(item['values'][0], numbers.Real):
0 commit comments