@@ -1867,17 +1867,29 @@ def test_1d_still_works(self):
18671867# ============================================================================
18681868
18691869
1870- class TestFromNumpyExplicitRayTypeMismatch :
1871- """Explicit ray_type with buffer element size mismatch ."""
1870+ class TestFromNumpyExplicitRayTypeCast :
1871+ """Explicit ray_type with different numpy dtype casts values correctly ."""
18721872
1873- def test_float32_as_f64_raises (self ):
1874- """float32 (4 bytes) → F64 (8 bytes): buffer too small ."""
1873+ def test_float32_as_f64 (self ):
1874+ """float32 → F64: values are cast, not reinterpreted ."""
18751875 arr = np .array ([1.0 , 2.0 ], dtype = np .float32 )
1876- with pytest . raises ( ValueError , match = "Buffer too small" ):
1877- t . Vector . from_numpy ( arr , ray_type = t . F64 )
1876+ vec = t . Vector . from_numpy ( arr , ray_type = t . F64 )
1877+ assert vec . to_list () == [ 1.0 , 2.0 ]
18781878
1879- def test_int16_as_i64_raises (self ):
1880- """int16 (2 bytes) → I64 (8 bytes): buffer too small ."""
1879+ def test_int16_as_i64 (self ):
1880+ """int16 → I64: values are cast, not reinterpreted ."""
18811881 arr = np .array ([1 , 2 ], dtype = np .int16 )
1882- with pytest .raises (ValueError , match = "Buffer too small" ):
1883- t .Vector .from_numpy (arr , ray_type = t .I64 )
1882+ vec = t .Vector .from_numpy (arr , ray_type = t .I64 )
1883+ assert vec .to_list () == [1 , 2 ]
1884+
1885+ def test_int64_as_i16 (self ):
1886+ """int64 → I16: values are cast, not reinterpreted."""
1887+ arr = np .array ([1 , 2 , 3 , 4 ], dtype = np .int64 )
1888+ vec = t .Vector .from_numpy (arr , ray_type = t .I16 )
1889+ assert vec .to_list () == [1 , 2 , 3 , 4 ]
1890+
1891+ def test_int64_as_i32 (self ):
1892+ """int64 → I32: values are cast, not reinterpreted."""
1893+ arr = np .array ([1 , 2 , 3 , 4 ], dtype = np .int64 )
1894+ vec = t .Vector .from_numpy (arr , ray_type = t .I32 )
1895+ assert vec .to_list () == [1 , 2 , 3 , 4 ]
0 commit comments