@@ -753,23 +753,28 @@ def test_contains(self):
753
753
assert Interval (3 , 5 ) not in i
754
754
assert Interval (- 1 , 0 , closed = 'left' ) not in i
755
755
756
- # To be removed, replaced by test_interval_new.py (see #16316, #16386)
757
- def testcontains (self ):
756
+ def test_contains_method (self ):
758
757
# can select values that are IN the range of a value
759
758
i = IntervalIndex .from_arrays ([0 , 1 ], [1 , 2 ])
760
759
761
- assert i . contains ( 0.1 )
762
- assert i .contains (0.5 )
763
- assert i . contains ( 1 )
764
- assert i .contains (Interval ( 0 , 1 ) )
765
- assert i . contains ( Interval ( 0 , 2 ) )
760
+ expected = np . array ([ False , False ], dtype = 'bool' )
761
+ actual = i .contains (0 )
762
+ tm . assert_numpy_array_equal ( actual , expected )
763
+ actual = i .contains (3 )
764
+ tm . assert_numpy_array_equal ( actual , expected )
766
765
767
- # these overlaps completely
768
- assert i .contains (Interval (0 , 3 ))
769
- assert i .contains (Interval (1 , 3 ))
766
+ expected = np .array ([True , False ], dtype = 'bool' )
767
+ actual = i .contains (0.5 )
768
+ tm .assert_numpy_array_equal (actual , expected )
769
+ actual = i .contains (1 )
770
+ tm .assert_numpy_array_equal (actual , expected )
770
771
771
- assert not i .contains (20 )
772
- assert not i .contains (- 20 )
772
+ # __contains__ not implemented for "interval in interval", follow
773
+ # that for the contains method for now
774
+ with pytest .raises (
775
+ NotImplementedError ,
776
+ match = 'contains not implemented for two' ):
777
+ i .contains (Interval (0 , 1 ))
773
778
774
779
def test_dropna (self , closed ):
775
780
@@ -939,11 +944,9 @@ def test_datetime(self, tz):
939
944
assert iv_false not in index
940
945
941
946
# .contains does check individual points
942
- assert not index .contains (Timestamp ('2000-01-01' , tz = tz ))
943
- assert index .contains (Timestamp ('2000-01-01T12' , tz = tz ))
944
- assert index .contains (Timestamp ('2000-01-02' , tz = tz ))
945
- assert index .contains (iv_true )
946
- assert not index .contains (iv_false )
947
+ assert not index .contains (Timestamp ('2000-01-01' , tz = tz )).any ()
948
+ assert index .contains (Timestamp ('2000-01-01T12' , tz = tz )).any ()
949
+ assert index .contains (Timestamp ('2000-01-02' , tz = tz )).any ()
947
950
948
951
# test get_indexer
949
952
start = Timestamp ('1999-12-31T12:00' , tz = tz )
0 commit comments