File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ def cartesian_product(X):
39
39
lenX = np .fromiter ((len (x ) for x in X ), dtype = np .intp )
40
40
cumprodX = np .cumproduct (lenX )
41
41
42
+ if np .any (cumprodX < 0 ):
43
+ raise ValueError ("Product space too large to allocate arrays!" )
44
+
42
45
a = np .roll (cumprodX , 1 )
43
46
a [0 ] = 1
44
47
Original file line number Diff line number Diff line change @@ -65,3 +65,13 @@ def test_invalid_input(self, X):
65
65
66
66
with pytest .raises (TypeError , match = msg ):
67
67
cartesian_product (X = X )
68
+
69
+ def test_exceed_product_space (self ):
70
+ # GH31355: raise useful error when produce space is too large
71
+ msg = "Product space too large to allocate arrays!"
72
+
73
+ with pytest .raises (ValueError , match = msg ):
74
+ dims = [np .arange (0 , 22 , dtype = np .int16 ) for i in range (12 )] + [
75
+ (np .arange (15128 , dtype = np .int16 )),
76
+ ]
77
+ cartesian_product (X = dims )
You can’t perform that action at this time.
0 commit comments