@@ -219,23 +219,21 @@ def test_roc_curve_binary_classification_prediction_matches_sklearn(session):
219
219
)
220
220
221
221
# sklearn returns float64 np arrays
222
- np_fpr = fpr .to_pandas ().astype ("float64" ).array
223
- np_tpr = tpr .to_pandas ().astype ("float64" ).array
222
+ np_fpr = fpr .to_pandas ().astype ("float64" ).array . to_numpy ()
223
+ np_tpr = tpr .to_pandas ().astype ("float64" ).array . to_numpy ()
224
224
np_thresholds = thresholds .to_pandas ().astype ("float64" ).array
225
225
226
226
np .testing .assert_array_equal (
227
227
# skip testing the first value, as it is redundant and inconsistent across sklearn versions
228
228
np_thresholds [1 :],
229
229
expected_thresholds [1 :],
230
230
)
231
- # TODO(b/340872435): fix type error
232
231
np .testing .assert_array_equal (
233
- np_fpr , # type: ignore
232
+ np_fpr ,
234
233
expected_fpr ,
235
234
)
236
- # TODO(b/340872435): fix type error
237
235
np .testing .assert_array_equal (
238
- np_tpr , # type: ignore
236
+ np_tpr ,
239
237
expected_tpr ,
240
238
)
241
239
@@ -316,23 +314,21 @@ def test_roc_curve_binary_classification_decision_matches_sklearn(session):
316
314
)
317
315
318
316
# sklearn returns float64 np arrays
319
- np_fpr = fpr .to_pandas ().astype ("float64" ).array
320
- np_tpr = tpr .to_pandas ().astype ("float64" ).array
317
+ np_fpr = fpr .to_pandas ().astype ("float64" ).array . to_numpy ()
318
+ np_tpr = tpr .to_pandas ().astype ("float64" ).array . to_numpy ()
321
319
np_thresholds = thresholds .to_pandas ().astype ("float64" ).array
322
320
323
321
np .testing .assert_array_equal (
324
322
# skip testing the first value, as it is redundant and inconsistent across sklearn versions
325
323
np_thresholds [1 :],
326
324
expected_thresholds [1 :],
327
325
)
328
- # TODO(b/340872435): fix type error
329
326
np .testing .assert_array_equal (
330
- np_fpr , # type: ignore
327
+ np_fpr ,
331
328
expected_fpr ,
332
329
)
333
- # TODO(b/340872435): fix type error
334
330
np .testing .assert_array_equal (
335
- np_tpr , # type: ignore
331
+ np_tpr ,
336
332
expected_tpr ,
337
333
)
338
334
@@ -519,14 +515,10 @@ def test_confusion_matrix_column_index(session):
519
515
).astype ("Int64" )
520
516
df = session .read_pandas (pd_df )
521
517
confusion_matrix = metrics .confusion_matrix (df [["y_true" ]], df [["y_pred" ]])
522
- # TODO(b/340872435): fix type error
523
- expected_pd_df = (
524
- pd .DataFrame ( # type: ignore
525
- {1 : [1 , 0 , 1 , 0 ], 2 : [0 , 0 , 2 , 0 ], 3 : [0 , 0 , 0 , 0 ], 4 : [0 , 1 , 0 , 1 ]}
526
- )
527
- .astype ("int64" )
528
- .set_index ([pd .Index ([1 , 2 , 3 , 4 ])])
529
- )
518
+ expected_pd_df = pd .DataFrame (
519
+ {1 : [1 , 0 , 1 , 0 ], 2 : [0 , 0 , 2 , 0 ], 3 : [0 , 0 , 0 , 0 ], 4 : [0 , 1 , 0 , 1 ]},
520
+ index = [1 , 2 , 3 , 4 ],
521
+ ).astype ("int64" )
530
522
pd .testing .assert_frame_equal (
531
523
confusion_matrix , expected_pd_df , check_index_type = False
532
524
)
@@ -562,9 +554,8 @@ def test_confusion_matrix_str_matches_sklearn(session):
562
554
expected_confusion_matrix = sklearn_metrics .confusion_matrix (
563
555
pd_df [["y_true" ]], pd_df [["y_pred" ]]
564
556
)
565
- # TODO(b/340872435): fix type error
566
- expected_pd_df = pd .DataFrame (expected_confusion_matrix ).set_index ( # type: ignore
567
- [pd .Index (["ant" , "bird" , "cat" ])]
557
+ expected_pd_df = pd .DataFrame (
558
+ expected_confusion_matrix , index = ["ant" , "bird" , "cat" ]
568
559
)
569
560
expected_pd_df .columns = pd .Index (["ant" , "bird" , "cat" ])
570
561
pd .testing .assert_frame_equal (
@@ -601,9 +592,8 @@ def test_recall_score(session):
601
592
}
602
593
).astype ("Int64" )
603
594
df = session .read_pandas (pd_df )
604
- # TODO(b/340872435): fix type error
605
595
recall = metrics .recall_score (
606
- df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None # type: ignore
596
+ df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None
607
597
)
608
598
expected_values = [1.000000 , 0.000000 , 0.666667 ]
609
599
expected_index = [0 , 1 , 2 ]
@@ -620,8 +610,7 @@ def test_recall_score_matches_sklearn(session):
620
610
}
621
611
).astype ("Int64" )
622
612
df = session .read_pandas (pd_df )
623
- # TODO(b/340872435): fix type error
624
- recall = metrics .recall_score (df [["y_true" ]], df [["y_pred" ]], average = None ) # type: ignore
613
+ recall = metrics .recall_score (df [["y_true" ]], df [["y_pred" ]], average = None )
625
614
expected_values = sklearn_metrics .recall_score (
626
615
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
627
616
)
@@ -638,8 +627,7 @@ def test_recall_score_str_matches_sklearn(session):
638
627
}
639
628
).astype ("str" )
640
629
df = session .read_pandas (pd_df )
641
- # TODO(b/340872435): fix type error
642
- recall = metrics .recall_score (df [["y_true" ]], df [["y_pred" ]], average = None ) # type: ignore
630
+ recall = metrics .recall_score (df [["y_true" ]], df [["y_pred" ]], average = None )
643
631
expected_values = sklearn_metrics .recall_score (
644
632
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
645
633
)
@@ -656,8 +644,7 @@ def test_recall_score_series(session):
656
644
}
657
645
).astype ("Int64" )
658
646
df = session .read_pandas (pd_df )
659
- # TODO(b/340872435): fix type error
660
- recall = metrics .recall_score (df ["y_true" ], df ["y_pred" ], average = None ) # type: ignore
647
+ recall = metrics .recall_score (df ["y_true" ], df ["y_pred" ], average = None )
661
648
expected_values = [1.000000 , 0.000000 , 0.666667 ]
662
649
expected_index = [0 , 1 , 2 ]
663
650
expected_recall = pd .Series (expected_values , index = expected_index )
@@ -673,9 +660,8 @@ def test_precision_score(session):
673
660
}
674
661
).astype ("Int64" )
675
662
df = session .read_pandas (pd_df )
676
- # TODO(b/340872435): fix type error
677
663
precision_score = metrics .precision_score (
678
- df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None # type: ignore
664
+ df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None
679
665
)
680
666
expected_values = [0.666667 , 0.000000 , 0.666667 ]
681
667
expected_index = [0 , 1 , 2 ]
@@ -696,7 +682,7 @@ def test_precision_score_matches_sklearn(session):
696
682
df = session .read_pandas (pd_df )
697
683
# TODO(b/340872435): fix type error
698
684
precision_score = metrics .precision_score (
699
- df [["y_true" ]], df [["y_pred" ]], average = None # type: ignore
685
+ df [["y_true" ]], df [["y_pred" ]], average = None
700
686
)
701
687
expected_values = sklearn_metrics .precision_score (
702
688
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
@@ -716,9 +702,8 @@ def test_precision_score_str_matches_sklearn(session):
716
702
}
717
703
).astype ("str" )
718
704
df = session .read_pandas (pd_df )
719
- # TODO(b/340872435): fix type error
720
705
precision_score = metrics .precision_score (
721
- df [["y_true" ]], df [["y_pred" ]], average = None # type: ignore
706
+ df [["y_true" ]], df [["y_pred" ]], average = None
722
707
)
723
708
expected_values = sklearn_metrics .precision_score (
724
709
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
@@ -738,8 +723,7 @@ def test_precision_score_series(session):
738
723
}
739
724
).astype ("Int64" )
740
725
df = session .read_pandas (pd_df )
741
- # TODO(b/340872435): fix type error
742
- precision_score = metrics .precision_score (df ["y_true" ], df ["y_pred" ], average = None ) # type: ignore
726
+ precision_score = metrics .precision_score (df ["y_true" ], df ["y_pred" ], average = None )
743
727
expected_values = [0.666667 , 0.000000 , 0.666667 ]
744
728
expected_index = [0 , 1 , 2 ]
745
729
expected_precision = pd .Series (expected_values , index = expected_index )
@@ -757,9 +741,8 @@ def test_f1_score(session):
757
741
}
758
742
).astype ("Int64" )
759
743
df = session .read_pandas (pd_df )
760
- # TODO(b/340872435): fix type error
761
744
f1_score = metrics .f1_score (
762
- df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None # type: ignore
745
+ df [["y_true_arbitrary_name" ]], df [["y_pred_arbitrary_name" ]], average = None
763
746
)
764
747
expected_values = [0.8 , 0.000000 , 0.666667 ]
765
748
expected_index = [0 , 1 , 2 ]
@@ -776,8 +759,7 @@ def test_f1_score_matches_sklearn(session):
776
759
}
777
760
).astype ("Int64" )
778
761
df = session .read_pandas (pd_df )
779
- # TODO(b/340872435): fix type error
780
- f1_score = metrics .f1_score (df [["y_true" ]], df [["y_pred" ]], average = None ) # type: ignore
762
+ f1_score = metrics .f1_score (df [["y_true" ]], df [["y_pred" ]], average = None )
781
763
expected_values = sklearn_metrics .f1_score (
782
764
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
783
765
)
@@ -794,8 +776,7 @@ def test_f1_score_str_matches_sklearn(session):
794
776
}
795
777
).astype ("str" )
796
778
df = session .read_pandas (pd_df )
797
- # TODO(b/340872435): fix type error
798
- f1_score = metrics .f1_score (df [["y_true" ]], df [["y_pred" ]], average = None ) # type: ignore
779
+ f1_score = metrics .f1_score (df [["y_true" ]], df [["y_pred" ]], average = None )
799
780
expected_values = sklearn_metrics .f1_score (
800
781
pd_df [["y_true" ]], pd_df [["y_pred" ]], average = None
801
782
)
@@ -812,8 +793,7 @@ def test_f1_score_series(session):
812
793
}
813
794
).astype ("Int64" )
814
795
df = session .read_pandas (pd_df )
815
- # TODO(b/340872435): fix type error
816
- f1_score = metrics .f1_score (df ["y_true" ], df ["y_pred" ], average = None ) # type: ignore
796
+ f1_score = metrics .f1_score (df ["y_true" ], df ["y_pred" ], average = None )
817
797
expected_values = [0.8 , 0.000000 , 0.666667 ]
818
798
expected_index = [0 , 1 , 2 ]
819
799
expected_f1 = pd .Series (expected_values , index = expected_index )
0 commit comments