@@ -362,3 +362,35 @@ def test_at_setitem_list_like_multiindex_row(self):
362362 df .at [("r1" , 0 ), "A" ] = [10 , 20 ]
363363 assert df .at [("r1" , 0 ), "A" ] == [10 , 20 ]
364364 assert df .at [("r2" , 1 ), "A" ] == 2
365+
366+ def test_at_setitem_ndarray_new_column (self ):
367+ # GH#61223: np.ndarray should be stored as a single cell in a new column
368+ df = DataFrame ({"A" : [1 , 2 , 3 ]}, index = ["a" , "b" , "c" ])
369+ arr = np .array ([10 , 20 , 30 ])
370+ df .at ["a" , "B" ] = arr
371+ stored = df .at ["a" , "B" ]
372+ assert isinstance (stored , np .ndarray )
373+ tm .assert_numpy_array_equal (stored , arr )
374+ assert df ["B" ].dtype == np .dtype ("object" )
375+ assert df .at ["b" , "B" ] is np .nan
376+
377+ def test_at_setitem_ndarray_existing_column (self ):
378+ # GH#61223: np.ndarray should be stored as a single cell even when the
379+ # existing column has a non-object dtype (column is cast to object)
380+ df = DataFrame ({"A" : [1 , 2 , 3 ]}, index = ["a" , "b" , "c" ])
381+ arr = np .array ([100 , 200 ])
382+ df .at ["b" , "A" ] = arr
383+ stored = df .at ["b" , "A" ]
384+ assert isinstance (stored , np .ndarray )
385+ tm .assert_numpy_array_equal (stored , arr )
386+ assert df ["A" ].dtype == np .dtype ("object" )
387+ assert df .at ["a" , "A" ] == 1
388+ assert df .at ["c" , "A" ] == 3
389+
390+ def test_at_setitem_dict_value_not_affected (self ):
391+ # GH#61223: dict values are excluded from the list-like single-cell path;
392+ # assigning a dict via .at should still raise ValueError as before
393+ # (existing behaviour must not change)
394+ df = DataFrame ({"A" : [1 , 2 , 3 ]}, index = ["a" , "b" , "c" ])
395+ with pytest .raises (ValueError , match = "Incompatible indexer" ):
396+ df .at ["a" , "A" ] = {"key" : "val" }
0 commit comments