File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -486,7 +486,10 @@ def from_vector(
486486 vector = vector .data # type: ignore
487487
488488 padding = 0 if padding is None else padding
489- assert isinstance (dtype , BinaryVectorDtype )
489+ if not isinstance (dtype , BinaryVectorDtype ):
490+ raise TypeError (
491+ "dtype must be a bson.BinaryVectorDtype, such as BinaryVectorDtype.FLOAT32"
492+ )
490493 metadata = struct .pack ("<sB" , dtype .value , padding )
491494
492495 if _NUMPY_AVAILABLE and isinstance (vector , np .ndarray ):
@@ -643,10 +646,10 @@ def _numpy_vector_to_bytes(
643646 if not _NUMPY_AVAILABLE :
644647 raise ImportError ("Converting numpy.ndarray to binary requires numpy to be installed." )
645648
646- assert isinstance (vector , np .ndarray )
647- assert (
648- vector .ndim == 1
649- ), "from_numpy_vector only supports 1D arrays as it creates a single vector."
649+ if not isinstance (vector , np .ndarray ):
650+ raise TypeError ( "Vector must be a numpy array." )
651+ if vector .ndim != 1 :
652+ raise ValueError ( "from_numpy_vector only supports 1D arrays as it creates a single vector." )
650653
651654 if dtype == BinaryVectorDtype .FLOAT32 :
652655 vector = vector .astype (np .dtype ("float32" ), copy = False )
You can’t perform that action at this time.
0 commit comments