@@ -125,18 +125,20 @@ def test_consistency():
125
125
126
126
127
127
@pytest .mark .slow
128
- def test_hash_collisions ():
128
+ def test_hash_collisions (monkeypatch ):
129
129
# non-smoke test that we don't get hash collisions
130
+ size_cutoff = 50
131
+ with monkeypatch .context () as m :
132
+ m .setattr (libindex , "_SIZE_CUTOFF" , size_cutoff )
133
+ index = MultiIndex .from_product (
134
+ [np .arange (8 ), np .arange (8 )], names = ["one" , "two" ]
135
+ )
136
+ result = index .get_indexer (index .values )
137
+ tm .assert_numpy_array_equal (result , np .arange (len (index ), dtype = "intp" ))
130
138
131
- index = MultiIndex .from_product (
132
- [np .arange (1000 ), np .arange (1000 )], names = ["one" , "two" ]
133
- )
134
- result = index .get_indexer (index .values )
135
- tm .assert_numpy_array_equal (result , np .arange (len (index ), dtype = "intp" ))
136
-
137
- for i in [0 , 1 , len (index ) - 2 , len (index ) - 1 ]:
138
- result = index .get_loc (index [i ])
139
- assert result == i
139
+ for i in [0 , 1 , len (index ) - 2 , len (index ) - 1 ]:
140
+ result = index .get_loc (index [i ])
141
+ assert result == i
140
142
141
143
142
144
def test_dims ():
@@ -170,22 +172,29 @@ def test_isna_behavior(idx):
170
172
pd .isna (idx )
171
173
172
174
173
- def test_large_multiindex_error ():
175
+ def test_large_multiindex_error (monkeypatch ):
174
176
# GH12527
175
- df_below_1000000 = pd .DataFrame (
176
- 1 , index = MultiIndex .from_product ([[1 , 2 ], range (499999 )]), columns = ["dest" ]
177
- )
178
- with pytest .raises (KeyError , match = r"^\(-1, 0\)$" ):
179
- df_below_1000000 .loc [(- 1 , 0 ), "dest" ]
180
- with pytest .raises (KeyError , match = r"^\(3, 0\)$" ):
181
- df_below_1000000 .loc [(3 , 0 ), "dest" ]
182
- df_above_1000000 = pd .DataFrame (
183
- 1 , index = MultiIndex .from_product ([[1 , 2 ], range (500001 )]), columns = ["dest" ]
184
- )
185
- with pytest .raises (KeyError , match = r"^\(-1, 0\)$" ):
186
- df_above_1000000 .loc [(- 1 , 0 ), "dest" ]
187
- with pytest .raises (KeyError , match = r"^\(3, 0\)$" ):
188
- df_above_1000000 .loc [(3 , 0 ), "dest" ]
177
+ size_cutoff = 50
178
+ with monkeypatch .context () as m :
179
+ m .setattr (libindex , "_SIZE_CUTOFF" , size_cutoff )
180
+ df_below_cutoff = pd .DataFrame (
181
+ 1 ,
182
+ index = MultiIndex .from_product ([[1 , 2 ], range (size_cutoff - 1 )]),
183
+ columns = ["dest" ],
184
+ )
185
+ with pytest .raises (KeyError , match = r"^\(-1, 0\)$" ):
186
+ df_below_cutoff .loc [(- 1 , 0 ), "dest" ]
187
+ with pytest .raises (KeyError , match = r"^\(3, 0\)$" ):
188
+ df_below_cutoff .loc [(3 , 0 ), "dest" ]
189
+ df_above_cutoff = pd .DataFrame (
190
+ 1 ,
191
+ index = MultiIndex .from_product ([[1 , 2 ], range (size_cutoff + 1 )]),
192
+ columns = ["dest" ],
193
+ )
194
+ with pytest .raises (KeyError , match = r"^\(-1, 0\)$" ):
195
+ df_above_cutoff .loc [(- 1 , 0 ), "dest" ]
196
+ with pytest .raises (KeyError , match = r"^\(3, 0\)$" ):
197
+ df_above_cutoff .loc [(3 , 0 ), "dest" ]
189
198
190
199
191
200
def test_mi_hashtable_populated_attribute_error (monkeypatch ):
0 commit comments