@@ -2085,12 +2085,14 @@ def test_datetime_timedelta_first_last(engine, func) -> None:
2085
2085
2086
2086
@requires_dask
2087
2087
@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 ):
2089
2091
import sparse
2090
2092
2091
2093
array = dask .array .ones ((2 , 12 ), chunks = (- 1 , 3 ))
2092
2094
func = "sum"
2093
- expected_groups = pd .Index ( np . arange ( 11 ) )
2095
+ expected_groups = pd .RangeIndex ( size )
2094
2096
by = dask .array .from_array (np .repeat (np .arange (6 ) * 2 , 2 ), chunks = (3 ,))
2095
2097
dense = np .zeros ((2 , 11 ))
2096
2098
dense [..., np .arange (6 ) * 2 ] = 2
@@ -2110,14 +2112,23 @@ def mocked_reindex(*args, **kwargs):
2110
2112
assert isinstance (res , sparse .COO )
2111
2113
return res
2112
2114
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
2121
2132
2122
2133
2123
2134
def test_sparse_errors ():
0 commit comments