@@ -658,6 +658,30 @@ def test_ufunc_coercions(self):
658658 exp = Float64Index ([0.5 , 1. , 1.5 , 2. , 2.5 ], name = 'x' )
659659 tm .assert_index_equal (result , exp )
660660
661+ def test_where (self ):
662+ i = self .create_index ()
663+ result = i .where (notna (i ))
664+ expected = i
665+ tm .assert_index_equal (result , expected )
666+
667+ _nan = i ._na_value
668+ cond = [False ] + [True ] * len (i [1 :])
669+ expected = Float64Index ([_nan ] + i [1 :].tolist ())
670+ result = i .where (cond )
671+ tm .assert_index_equal (result , expected )
672+
673+ def test_where_array_like (self ):
674+ i = self .create_index ()
675+
676+ _nan = i ._na_value
677+ cond = [False ] + [True ] * (len (i ) - 1 )
678+ klasses = [list , tuple , np .array , pd .Series ]
679+ expected = Float64Index ([_nan ] + i [1 :].tolist ())
680+
681+ for klass in klasses :
682+ result = i .where (klass (cond ))
683+ tm .assert_index_equal (result , expected )
684+
661685
662686class TestInt64Index (NumericInt ):
663687 _dtype = 'int64'
@@ -726,31 +750,6 @@ def test_coerce_list(self):
726750 arr = Index ([1 , 2 , 3 , 4 ], dtype = object )
727751 assert isinstance (arr , Index )
728752
729- def test_where (self ):
730- i = self .create_index ()
731- result = i .where (notna (i ))
732- expected = i
733- tm .assert_index_equal (result , expected )
734-
735- _nan = i ._na_value
736- cond = [False ] + [True ] * len (i [1 :])
737- expected = pd .Index ([_nan ] + i [1 :].tolist ())
738-
739- result = i .where (cond )
740- tm .assert_index_equal (result , expected )
741-
742- def test_where_array_like (self ):
743- i = self .create_index ()
744-
745- _nan = i ._na_value
746- cond = [False ] + [True ] * (len (i ) - 1 )
747- klasses = [list , tuple , np .array , pd .Series ]
748- expected = pd .Index ([_nan ] + i [1 :].tolist ())
749-
750- for klass in klasses :
751- result = i .where (klass (cond ))
752- tm .assert_index_equal (result , expected )
753-
754753 def test_get_indexer (self ):
755754 target = Int64Index (np .arange (10 ))
756755 indexer = self .index .get_indexer (target )
0 commit comments