@@ -545,18 +545,120 @@ def test_array_equivalent_str(dtype):
545
545
)
546
546
547
547
548
- def test_array_equivalent_nested ():
548
+ @pytest .mark .parametrize (
549
+ "strict_nan" , [pytest .param (True , marks = pytest .mark .xfail ), False ]
550
+ )
551
+ def test_array_equivalent_nested (strict_nan ):
549
552
# reached in groupby aggregations, make sure we use np.any when checking
550
553
# if the comparison is truthy
551
- left = np .array ([np .array ([50 , 70 , 90 ]), np .array ([20 , 30 , 40 ])], dtype = object )
552
- right = np .array ([np .array ([50 , 70 , 90 ]), np .array ([20 , 30 , 40 ])], dtype = object )
554
+ left = np .array ([np .array ([50 , 70 , 90 ]), np .array ([20 , 30 ])], dtype = object )
555
+ right = np .array ([np .array ([50 , 70 , 90 ]), np .array ([20 , 30 ])], dtype = object )
553
556
554
- assert array_equivalent (left , right , strict_nan = True )
555
- assert not array_equivalent (left , right [::- 1 ], strict_nan = True )
557
+ assert array_equivalent (left , right , strict_nan = strict_nan )
558
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
556
559
557
- left = np .array ([np .array ([50 , 50 , 50 ]), np .array ([40 , 40 , 40 ])], dtype = object )
560
+ left = np .empty (2 , dtype = object )
561
+ left [:] = [np .array ([50 , 70 , 90 ]), np .array ([20 , 30 , 40 ])]
562
+ right = np .empty (2 , dtype = object )
563
+ right [:] = [np .array ([50 , 70 , 90 ]), np .array ([20 , 30 , 40 ])]
564
+ assert array_equivalent (left , right , strict_nan = strict_nan )
565
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
566
+
567
+ left = np .array ([np .array ([50 , 50 , 50 ]), np .array ([40 , 40 ])], dtype = object )
558
568
right = np .array ([50 , 40 ])
559
- assert not array_equivalent (left , right , strict_nan = True )
569
+ assert not array_equivalent (left , right , strict_nan = strict_nan )
570
+
571
+
572
+ @pytest .mark .parametrize (
573
+ "strict_nan" , [pytest .param (True , marks = pytest .mark .xfail ), False ]
574
+ )
575
+ def test_array_equivalent_nested2 (strict_nan ):
576
+ # more than one level of nesting
577
+ left = np .array (
578
+ [
579
+ np .array ([np .array ([50 , 70 ]), np .array ([90 ])], dtype = object ),
580
+ np .array ([np .array ([20 , 30 ])], dtype = object ),
581
+ ],
582
+ dtype = object ,
583
+ )
584
+ right = np .array (
585
+ [
586
+ np .array ([np .array ([50 , 70 ]), np .array ([90 ])], dtype = object ),
587
+ np .array ([np .array ([20 , 30 ])], dtype = object ),
588
+ ],
589
+ dtype = object ,
590
+ )
591
+ assert array_equivalent (left , right , strict_nan = strict_nan )
592
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
593
+
594
+ left = np .array ([np .array ([np .array ([50 , 50 , 50 ])], dtype = object )], dtype = object )
595
+ right = np .array ([50 ])
596
+ assert not array_equivalent (left , right , strict_nan = strict_nan )
597
+
598
+
599
+ @pytest .mark .parametrize (
600
+ "strict_nan" , [pytest .param (True , marks = pytest .mark .xfail ), False ]
601
+ )
602
+ def test_array_equivalent_nested_list (strict_nan ):
603
+ left = np .array ([[50 , 70 , 90 ], [20 , 30 ]], dtype = object )
604
+ right = np .array ([[50 , 70 , 90 ], [20 , 30 ]], dtype = object )
605
+
606
+ assert array_equivalent (left , right , strict_nan = strict_nan )
607
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
608
+
609
+ left = np .array ([[50 , 50 , 50 ], [40 , 40 ]], dtype = object )
610
+ right = np .array ([50 , 40 ])
611
+ assert not array_equivalent (left , right , strict_nan = strict_nan )
612
+
613
+
614
+ @pytest .mark .xfail (reason = "failing" )
615
+ @pytest .mark .parametrize ("strict_nan" , [True , False ])
616
+ def test_array_equivalent_nested_mixed_list (strict_nan ):
617
+ # mixed arrays / lists in left and right
618
+ # https://github.com/pandas-dev/pandas/issues/50360
619
+ left = np .array ([np .array ([1 , 2 , 3 ]), np .array ([4 , 5 ])], dtype = object )
620
+ right = np .array ([[1 , 2 , 3 ], [4 , 5 ]], dtype = object )
621
+
622
+ assert array_equivalent (left , right , strict_nan = strict_nan )
623
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
624
+
625
+ # multiple levels of nesting
626
+ left = np .array (
627
+ [
628
+ np .array ([np .array ([1 , 2 , 3 ]), np .array ([4 , 5 ])], dtype = object ),
629
+ np .array ([np .array ([6 ]), np .array ([7 , 8 ]), np .array ([9 ])], dtype = object ),
630
+ ],
631
+ dtype = object ,
632
+ )
633
+ right = np .array ([[[1 , 2 , 3 ], [4 , 5 ]], [[6 ], [7 , 8 ], [9 ]]], dtype = object )
634
+ assert array_equivalent (left , right , strict_nan = strict_nan )
635
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
636
+
637
+ # same-length lists
638
+ subarr = np .empty (2 , dtype = object )
639
+ subarr [:] = [
640
+ np .array ([None , "b" ], dtype = object ),
641
+ np .array (["c" , "d" ], dtype = object ),
642
+ ]
643
+ left = np .array ([subarr , None ], dtype = object )
644
+ right = np .array ([list ([[None , "b" ], ["c" , "d" ]]), None ], dtype = object )
645
+ assert array_equivalent (left , right , strict_nan = strict_nan )
646
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
647
+
648
+
649
+ @pytest .mark .xfail (reason = "failing" )
650
+ @pytest .mark .parametrize ("strict_nan" , [True , False ])
651
+ def test_array_equivalent_nested_dicts (strict_nan ):
652
+ left = np .array ([{"f1" : 1 , "f2" : np .array (["a" , "b" ], dtype = object )}], dtype = object )
653
+ right = np .array (
654
+ [{"f1" : 1 , "f2" : np .array (["a" , "b" ], dtype = object )}], dtype = object
655
+ )
656
+ assert array_equivalent (left , right , strict_nan = strict_nan )
657
+ assert not array_equivalent (left , right [::- 1 ], strict_nan = strict_nan )
658
+
659
+ right2 = np .array ([{"f1" : 1 , "f2" : ["a" , "b" ]}], dtype = object )
660
+ assert array_equivalent (left , right2 , strict_nan = strict_nan )
661
+ assert not array_equivalent (left , right2 [::- 1 ], strict_nan = strict_nan )
560
662
561
663
562
664
def test_array_equivalent_index_with_tuples ():
0 commit comments