code: def build_matrix(data_id, data, cols, code_formatting_vars=None):
      if data[cols].isnull().values.any():
          data = data.corr(method="pearson")
          code = build_code_export(data_id)
          code.append(
              (
                  "corr_cols = [\n"
                  "\t'{corr_cols}'\n"
                  "]\n"
                  "corr_data = df[corr_cols]\n"
                  "{str_encodings}"
                  "corr_data = corr_data.corr(method='pearson')"
              ).format(
                  **dict_merge(
                      {"corr_cols": "", "str_encodings": ""},
                      code_formatting_vars,
                  )
              )
          )
      else:
          # using pandas.corr proved to be quite slow on large datasets so I moved to numpy:
          # https://stackoverflow.com/questions/48270953/pandas-corr-and-corrwith-very-slow
          data = np.corrcoef(
              data[cols].astype("float").values, rowvar=False
          )
          data = pd.DataFrame(data, columns=cols, index=cols)
          code = build_code_export(
              data_id,
              imports="import numpy as np\nimport pandas as pd\n\n",
          )
          code.append(
              (
                  "corr_cols = [\n"
                  "\t'{corr_cols}'\n"
                  "]\n"
                  "corr_data = df[corr_cols]\n"
                  "{str_encodings}"
                  "corr_data = np.corrcoef(corr_data.values, rowvar=False)\n"
                  "corr_data = pd.DataFrame(corr_data, columns=[corr_cols], index=[corr_cols])"
              ).format(
                  **dict_merge(
                      {"corr_cols": "", "str_encodings": ""},
                      code_formatting_vars,
                  )
              )
          )
  
      code = "\n".join(code)
      return data, code
  
file_path: dtale/dtale/correlations.py
imports: import numpy
  import pandas
  import dtale.global_state
  from dtale.code_export import build_code_export
  from dtale.utils import classify_type, dict_merge
label_desc: Use image node_id 2 for calling a global function with example usage: build_matrix(data_id, data, cols, code_formatting_vars) and returns: data,  code