We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ff235c0 commit b736724Copy full SHA for b736724
1 file changed
tests/readers/utils.py
@@ -138,6 +138,17 @@ def _rand_array(shape: Sequence[int], sparse: bool = False) -> np.ndarray:
138
a = np.zeros((rows, cols))
139
col_idxs = np.random.choice(cols, size=rows)
140
a[np.arange(rows), col_idxs] = np.random.random(rows)
141
+
142
+ # Ensure all columns have at least one non-zero value to avoid dimension mismatch
143
+ # in sparse array representations
144
+ for col in range(cols):
145
+ if not np.any(col_idxs == col):
146
+ # Pick a random row for this column
147
+ row = np.random.randint(0, rows)
148
+ # Only set if this row-col doesn't already have a value
149
+ if a[row, col] == 0:
150
+ a[row, col] = np.random.random()
151
152
return a.reshape(shape)
153
154
0 commit comments