@@ -2085,12 +2085,14 @@ def test_datetime_timedelta_first_last(engine, func) -> None:
20852085
20862086@requires_dask
20872087@requires_sparse
2088- def test_reindex_sparse ():
2088+ @pytest .mark .xdist_group (name = "sparse-group" )
2089+ @pytest .mark .parametrize ("size" , [2 ** 62 - 1 , 11 ])
2090+ def test_reindex_sparse (size ):
20892091 import sparse
20902092
20912093 array = dask .array .ones ((2 , 12 ), chunks = (- 1 , 3 ))
20922094 func = "sum"
2093- expected_groups = pd .Index ( np . arange ( 11 ) )
2095+ expected_groups = pd .RangeIndex ( size )
20942096 by = dask .array .from_array (np .repeat (np .arange (6 ) * 2 , 2 ), chunks = (3 ,))
20952097 dense = np .zeros ((2 , 11 ))
20962098 dense [..., np .arange (6 ) * 2 ] = 2
@@ -2110,14 +2112,23 @@ def mocked_reindex(*args, **kwargs):
21102112 assert isinstance (res , sparse .COO )
21112113 return res
21122114
2113- with patch ("flox.core.reindex_" ) as mocked_func :
2114- mocked_func .side_effect = mocked_reindex
2115- actual , * _ = groupby_reduce (
2116- array , by , func = func , reindex = reindex , expected_groups = expected_groups , fill_value = 0
2117- )
2118- assert_equal (actual , expected )
2119- # once during graph construction, 10 times afterward
2120- assert mocked_func .call_count > 1
2115+ # Define the error-raising property
2116+ def raise_error (self ):
2117+ raise AttributeError ("Access to '_data' is not allowed." )
2118+
2119+ with patch ("flox.core.reindex_" ) as mocked_reindex_func :
2120+ with patch .object (pd .RangeIndex , "_data" , property (raise_error )):
2121+ mocked_reindex_func .side_effect = mocked_reindex
2122+ actual , * _ = groupby_reduce (
2123+ array , by , func = func , reindex = reindex , expected_groups = expected_groups , fill_value = 0
2124+ )
2125+ if size == 11 :
2126+ assert_equal (actual , expected )
2127+ else :
2128+ actual .compute () # just compute
2129+
2130+ # once during graph construction, 10 times afterward
2131+ assert mocked_reindex_func .call_count > 1
21212132
21222133
21232134def test_sparse_errors ():
0 commit comments