From ce103b2092ebe4da78e01303eb2446a815687bc2 Mon Sep 17 00:00:00 2001 From: Haoyu Zhang Date: Wed, 25 Sep 2024 21:41:27 -0600 Subject: [PATCH] [impl]: Replace assertions with exceptions --- libs/ccc/coef/impl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/ccc/coef/impl.py b/libs/ccc/coef/impl.py index 0a0de10e..8f771476 100644 --- a/libs/ccc/coef/impl.py +++ b/libs/ccc/coef/impl.py @@ -624,7 +624,8 @@ def ccc( if x.ndim == 1 and (y is not None and y.ndim == 1): # both x and y are 1d arrays # TODO: remove assertions and raise exceptions - assert x.shape == y.shape, "x and y need to be of the same size" + if not x.shape == y.shape: + raise ValueError("x and y need to be of the same size") n_objects = x.shape[0] n_features = 2 @@ -640,10 +641,9 @@ def ccc( # plus we have the features data type (numerical, categorical, etc) if isinstance(x, np.ndarray): - assert get_feature_type_and_encode(x[0, :])[1], ( - "If data is a 2d numpy array, it has to be numerical. Use pandas.DataFrame if " - "you need to mix features with different data types" - ) + if not get_feature_type_and_encode(x[0, :])[1]: + raise ValueError("If data is a 2d numpy array, it has to be numerical. Use pandas.DataFrame if " + "you need to mix features with different data types") n_objects = x.shape[1] n_features = x.shape[0]