Skip to content

Commit b736724

Browse files
committed
Fix shape mismatch
1 parent ff235c0 commit b736724

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/readers/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ def _rand_array(shape: Sequence[int], sparse: bool = False) -> np.ndarray:
138138
a = np.zeros((rows, cols))
139139
col_idxs = np.random.choice(cols, size=rows)
140140
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+
141152
return a.reshape(shape)
142153

143154

0 commit comments

Comments
 (0)