@@ -397,3 +397,63 @@ def test_to_arrays_without_include_key(lang):
397397 names , langs = result
398398 assert isinstance (names , np .ndarray )
399399 assert isinstance (langs , np .ndarray )
400+
401+
402+ def test_to_arrays_inhomogeneous_shapes (schema_any ):
403+ """Test to_arrays handles arrays of different shapes correctly.
404+
405+ Regression test for https://github.com/datajoint/datajoint-python/issues/1380
406+ """
407+ table = schema .Longblob ()
408+ table .delete ()
409+
410+ # Insert arrays with different shapes that numpy would try to broadcast
411+ table .insert (
412+ [
413+ {"id" : 0 , "data" : np .random .randn (100 )}, # shape (100,)
414+ {"id" : 1 , "data" : np .random .randn (100 , 1 )}, # shape (100, 1)
415+ {"id" : 2 , "data" : np .random .randn (100 , 2 )}, # shape (100, 2)
416+ ]
417+ )
418+
419+ # This should not raise ValueError
420+ data = table .to_arrays ("data" , order_by = "id" )
421+
422+ # Should return object array with 3 elements
423+ assert data .dtype == object
424+ assert len (data ) == 3
425+
426+ # Each element should preserve its original shape
427+ assert data [0 ].shape == (100 ,)
428+ assert data [1 ].shape == (100 , 1 )
429+ assert data [2 ].shape == (100 , 2 )
430+
431+
432+ def test_to_arrays_inhomogeneous_shapes_second_axis (schema_any ):
433+ """Test to_arrays handles arrays differing on second axis.
434+
435+ Regression test for https://github.com/datajoint/datajoint-python/issues/1380
436+ """
437+ table = schema .Longblob ()
438+ table .delete ()
439+
440+ # Insert arrays with different shapes on second axis
441+ table .insert (
442+ [
443+ {"id" : 0 , "data" : np .random .randn (100 )}, # shape (100,)
444+ {"id" : 1 , "data" : np .random .randn (1 , 100 )}, # shape (1, 100)
445+ {"id" : 2 , "data" : np .random .randn (2 , 100 )}, # shape (2, 100)
446+ ]
447+ )
448+
449+ # This should not raise ValueError
450+ data = table .to_arrays ("data" , order_by = "id" )
451+
452+ # Should return object array with 3 elements
453+ assert data .dtype == object
454+ assert len (data ) == 3
455+
456+ # Each element should preserve its original shape
457+ assert data [0 ].shape == (100 ,)
458+ assert data [1 ].shape == (1 , 100 )
459+ assert data [2 ].shape == (2 , 100 )
0 commit comments