@@ -90,6 +90,34 @@ def test_range_slice_outofbounds(self, make_range):
90
90
tm .assert_frame_equal (df ["2013-06" :"2013-09" ], empty )
91
91
tm .assert_frame_equal (df ["2013-11" :"2013-12" ], empty )
92
92
93
+ @pytest .mark .parametrize ("make_range" , [date_range , period_range ])
94
+ def test_maybe_cast_slice_bound (self , make_range , frame_or_series ):
95
+ idx = make_range (start = "2013/10/01" , freq = "D" , periods = 10 )
96
+
97
+ obj = DataFrame (dict (units = [100 + i for i in range (10 )]), index = idx )
98
+ if frame_or_series is not DataFrame :
99
+ obj = obj ["units" ]
100
+
101
+ msg = (
102
+ f"cannot do slice indexing on { type (idx ).__name__ } with "
103
+ r"these indexers \[foo\] of type str"
104
+ )
105
+
106
+ # Check the lower-level calls are raising where expected.
107
+ with pytest .raises (TypeError , match = msg ):
108
+ idx ._maybe_cast_slice_bound ("foo" , "left" , "loc" )
109
+ with pytest .raises (TypeError , match = msg ):
110
+ idx .get_slice_bound ("foo" , "left" , "loc" )
111
+
112
+ with pytest .raises (TypeError , match = msg ):
113
+ obj ["2013/09/30" :"foo" ]
114
+ with pytest .raises (TypeError , match = msg ):
115
+ obj ["foo" :"2013/09/30" ]
116
+ with pytest .raises (TypeError , match = msg ):
117
+ obj .loc ["2013/09/30" :"foo" ]
118
+ with pytest .raises (TypeError , match = msg ):
119
+ obj .loc ["foo" :"2013/09/30" ]
120
+
93
121
def test_partial_slice_doesnt_require_monotonicity (self ):
94
122
# See also: DatetimeIndex test ofm the same name
95
123
dti = date_range ("2014-01-01" , periods = 30 , freq = "30D" )
0 commit comments