@@ -4656,6 +4656,38 @@ def test_from_frame():
46564656 res = from_frame (df , sort_rows = True , sort_columns = True )
46574657 assert_larray_equal (res , expected )
46584658
4659+ # h) with a MultiIndex with some missing combination and a fill_value which
4660+ # is not valid for all columns. This pattern broke for Pandas >= 3
4661+ # See issue #1166. In the user code, this issue came from, from_frame
4662+ # is used indirectly by read_excel and users are keeping only the
4663+ # numeric column (col2 in the test below) just after reading the array.
4664+ df = pd .DataFrame ({
4665+ 'idx1' : [0 , 0 , 1 ],
4666+ 'idx2' : ['a' , 'b' , 'a' ],
4667+ 'col1' : ['a' , 'a' , 'a' ],
4668+ 'col2' : [1 , 1 , 1 ]
4669+ }).set_index (['idx1' , 'idx2' ])
4670+ # TODO: we should have this warning, but before that we need more
4671+ # functionality to let users do something about it.
4672+ # See comment in inout/pandas.py:cartesian_product_df
4673+ # msg = ("fill_value is not valid for all columns because it is a "
4674+ # "(non-NaN) number but the 'col1' column has string dtype. That "
4675+ # "column will converted to object dtype to avoid errors but this "
4676+ # "may cause performance issues.")
4677+ # with must_warn(FutureWarning, msg=msg):
4678+ # from_frame(df, fill_value=-1)
4679+ res = from_frame (df , fill_value = - 1 )
4680+ expected_data = [[['a' , 1 ],
4681+ ['a' , 1 ]],
4682+ [['a' , 1 ],
4683+ [- 1 , - 1 ]]]
4684+ expected_axes = [
4685+ # third axis is anonymous
4686+ Axis ('idx1=0,1' ), Axis ('idx2=a,b' ), Axis ('col1,col2' )
4687+ ]
4688+ expected = Array (expected_data , expected_axes , dtype = object )
4689+ assert_larray_equal (res , expected )
4690+
46594691
46604692def test_asarray ():
46614693 series = pd .Series ([0 , 1 , 2 ], ['a0' , 'a1' , 'a2' ], name = 'a' )
0 commit comments