code: def psi(
      dist1: Union[np.ndarray, pd.Series],
      dist2: Union[np.ndarray, pd.Series],
      min_category_size_ratio: float = 0,
      max_num_categories: int = None,
      sort_by: str = "dist1",
      from_freqs: bool = False,
  ) -> float:
      """
      Calculate the PSI (Population Stability Index).
  
      See https://www.lexjansen.com/wuss/2017/47_Final_Paper_PDF.pdf
  
      Parameters
      ----------
      dist1 : Union[np.ndarray, pd.Series]
          array of numerical values.
      dist2 : Union[np.ndarray, pd.Series]
          array of numerical values to compare dist1 to.
      min_category_size_ratio: float, default 0.01
          minimum size ratio for categories. Categories with size ratio lower than this number are binned
          into an "Other" category.
      max_num_categories: int, default: None
          max number of allowed categories. If there are more categories than this number, categories are ordered by
          magnitude and all the smaller categories are binned into an "Other" category.
          If max_num_categories=None, there is no limit.
          > Note that if this parameter is used, the ordering of categories (and by extension, the decision which
          categories are kept by name and which are binned to the "Other" category) is done by default according to the
          values of dist1, which is treated as the "expected" distribution. This behavior can be changed by using the
          sort_by parameter.
      sort_by: str, default: 'dist1'
          Specify how categories should be sorted, affecting which categories will get into the "Other" category.
          Possible values:
          - 'dist1': Sort by the largest dist1 categories.
          - 'dist2': Sort by the largest dist2 categories.
          - 'difference': Sort by the largest difference between categories.
          > Note that this parameter has no effect if max_num_categories = None or there are not enough unique categories.
      from_freqs: bool, default: False
          Whether the data is already in the form of frequencies.
      Returns
      -------
      psi
          The PSI score
      """
      if from_freqs:
          expected_counts, actual_counts = dist1, dist2
      else:
          (
              expected_counts,
              actual_counts,
              _,
          ) = preprocess_2_cat_cols_to_same_bins(
              dist1,
              dist2,
              min_category_size_ratio,
              max_num_categories,
              sort_by,
          )
      size_expected, size_actual = sum(expected_counts), sum(
          actual_counts
      )
      psi_value = 0
      for i in range(len(expected_counts)):
          # In order for the value not to diverge, we cap our min percentage value
          e_perc = max(
              expected_counts[i] / size_expected, PSI_MIN_PERCENTAGE
          )
          a_perc = max(
              actual_counts[i] / size_actual, PSI_MIN_PERCENTAGE
          )
          value = (e_perc - a_perc) * np.log(e_perc / a_perc)
          psi_value += value
  
      return psi_value
  
imports: from numbers import Number
  from typing import Dict, Optional, Tuple, Union
  import numpy
  import pandas
  from plotly.graph_objs import Figure
  from plotly.subplots import make_subplots
  from scipy.stats import chi2_contingency, wasserstein_distance
  from deepchecks.core import ConditionCategory, ConditionResult
  from deepchecks.core.errors import DeepchecksValueError, NotEnoughSamplesError
  from deepchecks.utils.dict_funcs import get_dict_entry_by_value
  from deepchecks.utils.distribution.plot import CategoriesSortingKind, drift_score_bar_traces, feature_distribution_traces
  from deepchecks.utils.distribution.preprocessing import preprocess_2_cat_cols_to_same_bins
  from deepchecks.utils.plot import DEFAULT_DATASET_NAMES
  from deepchecks.utils.strings import format_number
label_desc: Use image node_id 6 for calling a global function with example usage: psi(dist1, dist2, min_category_size_ratio, max_num_categories, sort_by, from_freqs) and returns: psi_value