From 8e7f8b2147886e1d01e3a5c5fa8423cf8e781b76 Mon Sep 17 00:00:00 2001 From: Alex Barros Date: Thu, 13 Oct 2022 14:10:19 -0300 Subject: [PATCH] fix: cramer's correlation fails with missings vals (#1109) --- src/pandas_profiling/model/pandas/correlations_pandas.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pandas_profiling/model/pandas/correlations_pandas.py b/src/pandas_profiling/model/pandas/correlations_pandas.py index 25db58834..156702bc8 100644 --- a/src/pandas_profiling/model/pandas/correlations_pandas.py +++ b/src/pandas_profiling/model/pandas/correlations_pandas.py @@ -97,9 +97,12 @@ def pandas_cramers_compute( for name1, name2 in itertools.combinations(categoricals, 2): confusion_matrix = pd.crosstab(df[name1], df[name2]) - correlation_matrix.loc[name2, name1] = _cramers_corrected_stat( - confusion_matrix, correction=True - ) + if confusion_matrix.empty: + correlation_matrix.loc[name2, name1] = np.nan + else: + correlation_matrix.loc[name2, name1] = _cramers_corrected_stat( + confusion_matrix, correction=True + ) correlation_matrix.loc[name1, name2] = correlation_matrix.loc[name2, name1] return correlation_matrix