@@ -598,3 +598,49 @@ def test_calculate_sorted_index_offsets_raises_when_not_sorted():
598598 index = pd .Index ([1 , 2 , 1 , 2 , 3 , 3 , 4 , 4 , 4 ])
599599 with pytest .raises (ValueError ):
600600 packer .calculate_sorted_index_offsets (index )
601+
602+
603+ @pytest .mark .parametrize (
604+ "index" ,
605+ [
606+ pd .Index ([1.0 , 1.0 , 2.0 , 2.0 , np .nan ]),
607+ pd .MultiIndex .from_arrays (([1 , 1 , 2 , 2 , 2 ], [1.0 , 2.0 , np .nan , 1.0 , 2.0 ])),
608+ ],
609+ )
610+ def test_pack_flat_raises_with_nan_in_index (index ):
611+ """Test pack_flat() raises informative error when index contains NaN values.
612+
613+ This is a regression test for https://github.com/lincc-frameworks/nested-pandas/issues/440
614+ """
615+ df = pd .DataFrame (
616+ data = {
617+ "a" : [1 , 2 , 3 , 4 , 5 ],
618+ "b" : [0 , 1 , 0 , 1 , 0 ],
619+ },
620+ index = index ,
621+ )
622+ with pytest .raises (ValueError , match = "The index contains NaN values" ):
623+ packer .pack_flat (df )
624+
625+
626+ @pytest .mark .parametrize (
627+ "col_data,col_dtype" ,
628+ [
629+ ([1.0 , 1.0 , 2.0 , 2.0 , np .nan ], None ),
630+ ([1.0 , 1.0 , 2.0 , 2.0 , None ], pd .ArrowDtype (pa .float64 ())),
631+ ],
632+ )
633+ def test_pack_flat_raises_with_nan_in_on_column (col_data , col_dtype ):
634+ """Test pack_flat() raises informative error when 'on' column contains NaN values.
635+
636+ This is a regression test for https://github.com/lincc-frameworks/nested-pandas/issues/440
637+ """
638+ df = pd .DataFrame (
639+ data = {
640+ "a" : [1 , 2 , 3 , 4 , 5 ],
641+ "b" : [0 , 1 , 0 , 1 , 0 ],
642+ "c" : pd .array (col_data , dtype = col_dtype ),
643+ },
644+ )
645+ with pytest .raises (ValueError , match = r"Column\(s\) \['c'\] contain NaN values" ):
646+ packer .pack_flat (df , on = "c" )
0 commit comments