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