Skip to content

Commit

Permalink
add error message when indices can't be casted to int32.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoineSchmidtQC committed Sep 17, 2024
1 parent 3fc0080 commit 688db36
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tabmat/categorical_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ def __init__(
self._has_missings = False

self.drop_first = drop_first
self.indices = indices.astype(np.int32, copy=False)
try:
self.indices = indices.astype(np.int32, copy=False)
except ValueError:
raise ValueError(
"When creating a CategoricalMatrix with indices and categories, "
"indices must be castable to a numpy int32 dtype."
)
self.shape = (len(self.indices), len(self.categories) - int(drop_first))
self.x_csc = None
self.dtype = np.dtype(dtype)
Expand Down

0 comments on commit 688db36

Please sign in to comment.