prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/pandas_profiling/model/pandas/correlations_pandas.py`
  Content:
  ```
  1 """Correlations between variables."""
  2 import itertools
  3 import warnings
  4 from typing import Optional
  5 
  6 import numpy as np
  7 import pandas as pd
  8 from scipy import stats
  9 
  10 from pandas_profiling.config import Settings
  11 from pandas_profiling.model.correlations import (
  12     Cramers,
  13     Kendall,
  14     Pearson,
  15     PhiK,
  16     Spearman,
  17 )
  18 
  19 
  20 @Spearman.compute.register(Settings, pd.DataFrame, dict)
  21 def pandas_spearman_compute(
  22     config: Settings, df: pd.DataFrame, summary: dict
  23 ) -> Optional[pd.DataFrame]:
  24     return df.corr(method="spearman")
  25 
  26 
  27 @Pearson.compute.register(Settings, pd.DataFrame, dict)
  28 def pandas_pearson_compute(
  29     config: Settings, df: pd.DataFrame, summary: dict
  30 ) -> Optional[pd.DataFrame]:
  31     return df.corr(method="pearson")
  32 
  33 
  34 @Kendall.compute.register(Settings, pd.DataFrame, dict)
  35 def pandas_kendall_compute(
  36     config: Settings, df: pd.DataFrame, summary: dict
  37 ) -> Optional[pd.DataFrame]:
  38     return df.corr(method="kendall")
  39 
  40 
  41 def _cramers_corrected_stat(confusion_matrix: pd.DataFrame, correction: bool) -> float:
  42     """Calculate the Cramer's V corrected stat for two variables.
  43 
  44     Args:
  45         confusion_matrix: Crosstab between two variables.
  46         correction: Should the correction be applied?
  47 
  48     Returns:
  49         The Cramer's V corrected stat for the two variables.
  50     """
  51     chi2 = stats.chi2_contingency(confusion_matrix, correction=correction)[0]
  52     n = confusion_matrix.sum().sum()
  53     phi2 = chi2 / n
  54     r = confusion_matrix.shape[0]
  55     k = confusion_matrix.shape[1] if len(confusion_matrix.shape) > 1 else 1
  56 
  57     # Deal with NaNs later on
  58     with np.errstate(divide="ignore", invalid="ignore"):
  59         phi2corr = max(0.0, phi2 - ((k - 1.0) * (r - 1.0)) / (n - 1.0))
  60         rcorr = r - ((r - 1.0) ** 2.0) / (n - 1.0)
  61         kcorr = k - ((k - 1.0) ** 2.0) / (n - 1.0)
  62         rkcorr = min((kcorr - 1.0), (rcorr - 1.0))
  63         if rkcorr == 0.0:
  64             corr = 1.0
  65         else:
  66             corr = np.sqrt(phi2corr / rkcorr)
  67     return corr
  68 
  69 
  70 @Cramers.compute.register(Settings, pd.DataFrame, dict)
  71 def pandas_cramers_compute(
  72     config: Settings, df: pd.DataFrame, summary: dict
  73 ) -> Optional[pd.DataFrame]:
  74     threshold = config.categorical_maximum_correlation_distinct
  75 
  76     # `index` and `columns` must not be a set since Pandas 1.5,
  77     # so convert it to a list. The order of the list is arbitrary.
  78     categoricals = list(
  79         {
  80             key
  81             for key, value in summary.items()
  82             if value["type"] in {"Categorical", "Boolean"}
  83             and value["n_distinct"] <= threshold
  84         }
  85     )
  86 
  87     if len(categoricals) <= 1:
  88         return None
  89 
  90     matrix = np.zeros((len(categoricals), len(categoricals)))
  91     np.fill_diagonal(matrix, 1.0)
  92     correlation_matrix = pd.DataFrame(
  93         matrix,
  94         index=categoricals,
  95         columns=categoricals,
  96     )
  97 
  98     for name1, name2 in itertools.combinations(categoricals, 2):
  99         confusion_matrix = pd.crosstab(df[name1], df[name2])
  100         correlation_matrix.loc[name2, name1] = _cramers_corrected_stat(
  101             confusion_matrix, correction=True
  102         )
  103         correlation_matrix.loc[name1, name2] = correlation_matrix.loc[name2, name1]
  104     return correlation_matrix
  105 
  106 
  107 @PhiK.compute.register(Settings, pd.DataFrame, dict)
  108 def pandas_phik_compute(
  109     config: Settings, df: pd.DataFrame, summary: dict
  110 ) -> Optional[pd.DataFrame]:
  111     df_cols_dict = {i: list(df.columns).index(i) for i in df.columns}
  112 
  113     intcols = {
  114         key
  115         for key, value in summary.items()
  116         # DateTime currently excluded
  117         # In some use cases, it makes sense to convert it to interval
  118         # See https://github.com/KaveIO/PhiK/issues/7
  119         if value["type"] == "Numeric" and 1 < value["n_distinct"]
  120     }
  121 
  122     selcols = {
  123         key
  124         for key, value in summary.items()
  125         if value["type"] != "Unsupported"
  126         and 1 < value["n_distinct"] <= config.categorical_maximum_correlation_distinct
  127     }
  128     selcols = selcols.union(intcols)
  129     selected_cols = sorted(selcols, key=lambda i: df_cols_dict[i])
  130 
  131     if len(selected_cols) <= 1:
  132         return None
  133 
  134     with warnings.catch_warnings():
  135         warnings.simplefilter("ignore")
  136         from phik import phik_matrix
  137 
  138         correlation = phik_matrix(df[selected_cols], interval_cols=list(intcols))
  139 
  140     return correlation
  141
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 @@
   
       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
  
verification_info: {"golden_diff": "diff --git a/src/pandas_profiling/model/pandas/correlations_pandas.py b/src/pandas_profiling/model/pandas/correlations_pandas.py\n--- a/src/pandas_profiling/model/pandas/correlations_pandas.py\n+++ b/src/pandas_profiling/model/pandas/correlations_pandas.py\n@@ -97,9 +97,12 @@\n \n     for name1, name2 in itertools.combinations(categoricals, 2):\n         confusion_matrix = pd.crosstab(df[name1], df[name2])\n-        correlation_matrix.loc[name2, name1] = _cramers_corrected_stat(\n-            confusion_matrix, correction=True\n-        )\n+        if confusion_matrix.empty:\n+            correlation_matrix.loc[name2, name1] = np.nan\n+        else:\n+            correlation_matrix.loc[name2, name1] = _cramers_corrected_stat(\n+                confusion_matrix, correction=True\n+            )\n         correlation_matrix.loc[name1, name2] = correlation_matrix.loc[name2, name1]\n     return correlation_matrix\n", "issue": "Cramer correlation matrix is not computed\n/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.\r\nTo hide this warning, disable the calculation\r\n(using `df.profile_report(correlations={\"cramers\": {\"calculate\": False}})`\r\nIf this is problematic for your use case, please report this as an issue:\r\nhttps://github.com/ydataai/pandas-profiling/issues\r\n(include the error message: 'No data; `observed` has size 0.')\r\n pls help. My dataset is https://busan302.mycourses.work/data/house_price_train.csv\n", "before_files": [{"content": "\"\"\"Correlations between variables.\"\"\"\nimport itertools\nimport warnings\nfrom typing import Optional\n\nimport numpy as np\nimport pandas as pd\nfrom scipy import stats\n\nfrom pandas_profiling.config import Settings\nfrom pandas_profiling.model.correlations import (\n    Cramers,\n    Kendall,\n    Pearson,\n    PhiK,\n    Spearman,\n)\n\n\n@Spearman.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_spearman_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"spearman\")\n\n\n@Pearson.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_pearson_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"pearson\")\n\n\n@Kendall.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_kendall_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"kendall\")\n\n\ndef _cramers_corrected_stat(confusion_matrix: pd.DataFrame, correction: bool) -> float:\n    \"\"\"Calculate the Cramer's V corrected stat for two variables.\n\n    Args:\n        confusion_matrix: Crosstab between two variables.\n        correction: Should the correction be applied?\n\n    Returns:\n        The Cramer's V corrected stat for the two variables.\n    \"\"\"\n    chi2 = stats.chi2_contingency(confusion_matrix, correction=correction)[0]\n    n = confusion_matrix.sum().sum()\n    phi2 = chi2 / n\n    r = confusion_matrix.shape[0]\n    k = confusion_matrix.shape[1] if len(confusion_matrix.shape) > 1 else 1\n\n    # Deal with NaNs later on\n    with np.errstate(divide=\"ignore\", invalid=\"ignore\"):\n        phi2corr = max(0.0, phi2 - ((k - 1.0) * (r - 1.0)) / (n - 1.0))\n        rcorr = r - ((r - 1.0) ** 2.0) / (n - 1.0)\n        kcorr = k - ((k - 1.0) ** 2.0) / (n - 1.0)\n        rkcorr = min((kcorr - 1.0), (rcorr - 1.0))\n        if rkcorr == 0.0:\n            corr = 1.0\n        else:\n            corr = np.sqrt(phi2corr / rkcorr)\n    return corr\n\n\n@Cramers.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_cramers_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    threshold = config.categorical_maximum_correlation_distinct\n\n    # `index` and `columns` must not be a set since Pandas 1.5,\n    # so convert it to a list. The order of the list is arbitrary.\n    categoricals = list(\n        {\n            key\n            for key, value in summary.items()\n            if value[\"type\"] in {\"Categorical\", \"Boolean\"}\n            and value[\"n_distinct\"] <= threshold\n        }\n    )\n\n    if len(categoricals) <= 1:\n        return None\n\n    matrix = np.zeros((len(categoricals), len(categoricals)))\n    np.fill_diagonal(matrix, 1.0)\n    correlation_matrix = pd.DataFrame(\n        matrix,\n        index=categoricals,\n        columns=categoricals,\n    )\n\n    for name1, name2 in itertools.combinations(categoricals, 2):\n        confusion_matrix = pd.crosstab(df[name1], df[name2])\n        correlation_matrix.loc[name2, name1] = _cramers_corrected_stat(\n            confusion_matrix, correction=True\n        )\n        correlation_matrix.loc[name1, name2] = correlation_matrix.loc[name2, name1]\n    return correlation_matrix\n\n\n@PhiK.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_phik_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    df_cols_dict = {i: list(df.columns).index(i) for i in df.columns}\n\n    intcols = {\n        key\n        for key, value in summary.items()\n        # DateTime currently excluded\n        # In some use cases, it makes sense to convert it to interval\n        # See https://github.com/KaveIO/PhiK/issues/7\n        if value[\"type\"] == \"Numeric\" and 1 < value[\"n_distinct\"]\n    }\n\n    selcols = {\n        key\n        for key, value in summary.items()\n        if value[\"type\"] != \"Unsupported\"\n        and 1 < value[\"n_distinct\"] <= config.categorical_maximum_correlation_distinct\n    }\n    selcols = selcols.union(intcols)\n    selected_cols = sorted(selcols, key=lambda i: df_cols_dict[i])\n\n    if len(selected_cols) <= 1:\n        return None\n\n    with warnings.catch_warnings():\n        warnings.simplefilter(\"ignore\")\n        from phik import phik_matrix\n\n        correlation = phik_matrix(df[selected_cols], interval_cols=list(intcols))\n\n    return correlation\n", "path": "src/pandas_profiling/model/pandas/correlations_pandas.py"}], "after_files": [{"content": "\"\"\"Correlations between variables.\"\"\"\nimport itertools\nimport warnings\nfrom typing import Optional\n\nimport numpy as np\nimport pandas as pd\nfrom scipy import stats\n\nfrom pandas_profiling.config import Settings\nfrom pandas_profiling.model.correlations import (\n    Cramers,\n    Kendall,\n    Pearson,\n    PhiK,\n    Spearman,\n)\n\n\n@Spearman.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_spearman_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"spearman\")\n\n\n@Pearson.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_pearson_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"pearson\")\n\n\n@Kendall.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_kendall_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    return df.corr(method=\"kendall\")\n\n\ndef _cramers_corrected_stat(confusion_matrix: pd.DataFrame, correction: bool) -> float:\n    \"\"\"Calculate the Cramer's V corrected stat for two variables.\n\n    Args:\n        confusion_matrix: Crosstab between two variables.\n        correction: Should the correction be applied?\n\n    Returns:\n        The Cramer's V corrected stat for the two variables.\n    \"\"\"\n    chi2 = stats.chi2_contingency(confusion_matrix, correction=correction)[0]\n    n = confusion_matrix.sum().sum()\n    phi2 = chi2 / n\n    r = confusion_matrix.shape[0]\n    k = confusion_matrix.shape[1] if len(confusion_matrix.shape) > 1 else 1\n\n    # Deal with NaNs later on\n    with np.errstate(divide=\"ignore\", invalid=\"ignore\"):\n        phi2corr = max(0.0, phi2 - ((k - 1.0) * (r - 1.0)) / (n - 1.0))\n        rcorr = r - ((r - 1.0) ** 2.0) / (n - 1.0)\n        kcorr = k - ((k - 1.0) ** 2.0) / (n - 1.0)\n        rkcorr = min((kcorr - 1.0), (rcorr - 1.0))\n        if rkcorr == 0.0:\n            corr = 1.0\n        else:\n            corr = np.sqrt(phi2corr / rkcorr)\n    return corr\n\n\n@Cramers.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_cramers_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    threshold = config.categorical_maximum_correlation_distinct\n\n    # `index` and `columns` must not be a set since Pandas 1.5,\n    # so convert it to a list. The order of the list is arbitrary.\n    categoricals = list(\n        {\n            key\n            for key, value in summary.items()\n            if value[\"type\"] in {\"Categorical\", \"Boolean\"}\n            and value[\"n_distinct\"] <= threshold\n        }\n    )\n\n    if len(categoricals) <= 1:\n        return None\n\n    matrix = np.zeros((len(categoricals), len(categoricals)))\n    np.fill_diagonal(matrix, 1.0)\n    correlation_matrix = pd.DataFrame(\n        matrix,\n        index=categoricals,\n        columns=categoricals,\n    )\n\n    for name1, name2 in itertools.combinations(categoricals, 2):\n        confusion_matrix = pd.crosstab(df[name1], df[name2])\n        if confusion_matrix.empty:\n            correlation_matrix.loc[name2, name1] = np.nan\n        else:\n            correlation_matrix.loc[name2, name1] = _cramers_corrected_stat(\n                confusion_matrix, correction=True\n            )\n        correlation_matrix.loc[name1, name2] = correlation_matrix.loc[name2, name1]\n    return correlation_matrix\n\n\n@PhiK.compute.register(Settings, pd.DataFrame, dict)\ndef pandas_phik_compute(\n    config: Settings, df: pd.DataFrame, summary: dict\n) -> Optional[pd.DataFrame]:\n    df_cols_dict = {i: list(df.columns).index(i) for i in df.columns}\n\n    intcols = {\n        key\n        for key, value in summary.items()\n        # DateTime currently excluded\n        # In some use cases, it makes sense to convert it to interval\n        # See https://github.com/KaveIO/PhiK/issues/7\n        if value[\"type\"] == \"Numeric\" and 1 < value[\"n_distinct\"]\n    }\n\n    selcols = {\n        key\n        for key, value in summary.items()\n        if value[\"type\"] != \"Unsupported\"\n        and 1 < value[\"n_distinct\"] <= config.categorical_maximum_correlation_distinct\n    }\n    selcols = selcols.union(intcols)\n    selected_cols = sorted(selcols, key=lambda i: df_cols_dict[i])\n\n    if len(selected_cols) <= 1:\n        return None\n\n    with warnings.catch_warnings():\n        warnings.simplefilter(\"ignore\")\n        from phik import phik_matrix\n\n        correlation = phik_matrix(df[selected_cols], interval_cols=list(intcols))\n\n    return correlation\n", "path": "src/pandas_profiling/model/pandas/correlations_pandas.py"}]}