Repository: ydataai/ydata-profiling

Issue:
Cramer correlation matrix is not computed
/usr/local/lib/python3.7/dist-packages/pandas_profiling/model/correlations.py:61: UserWarning:There was an attempt to calculate the cramers correlation, but this failed.
To hide this warning, disable the calculation
(using `df.profile_report(correlations={"cramers": {"calculate": False}})`
If this is problematic for your use case, please report this as an issue:
https://github.com/ydataai/pandas-profiling/issues
(include the error message: 'No data; `observed` has size 0.')
 pls help. My dataset is https://busan302.mycourses.work/data/house_price_train.csv


Discussion:
> /usr/local/lib/python3.7/dist-packages/pandas_profiling/model/correlations.py:61: UserWarning:There was an attempt to calculate the cramers correlation, but this failed. To hide this warning, disable the calculation (using `df.profile_report(correlations={"cramers": {"calculate": False}})` If this is problematic for your use case, please report this as an issue: https://github.com/ydataai/pandas-profiling/issues (include the error message: 'No data; `observed` has size 0.') pls help. My dataset is https://busan302.mycourses.work/data/house_price_train.csv

Hi @bdao568 thank you for submitting your support request. 
Can you please share the `pandas-profiling` version you are using?
> > /usr/local/lib/python3.7/dist-packages/pandas_profiling/model/correlations.py:61: UserWarning:There was an attempt to calculate the cramers correlation, but this failed. To hide this warning, disable the calculation (using `df.profile_report(correlations={"cramers": {"calculate": False}})` If this is problematic for your use case, please report this as an issue: https://github.com/ydataai/pandas-profiling/issues (include the error message: 'No data; `observed` has size 0.') pls help. My dataset is https://busan302.mycourses.work/data/house_price_train.csv
> 
> Hi @bdao568 thank you for submitting your support request. Can you please share the `pandas-profiling` version you are using?

Im using this particular one https://github.com/pandas-profiling/pandas-profiling/archive/master.zip

Can you please share the stack trace as well as the sample of your code?
> Can you please share the stack trace as well as the sample of your code?

https://colab.research.google.com/drive/1GKbCuAxNL91MN6jyNlyHn6zfnB7tcRCN?usp=sharing
Thank you! I'll take a look into it and get back to you.
@bdao568 it seems there is a bug related with Cramer's calculation for your dataset. 

I was able to generate the html report with no Cramer correlation matrix calculated. This is the workaround while we try to better understand the root cause.

Resolving patch:
diff --git a/src/pandas_profiling/model/pandas/correlations_pandas.py b/src/pandas_profiling/model/pandas/correlations_pandas.py
--- 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
 


Test patch: