code: def earth_movers_distance(
      dist1: Union[np.ndarray, pd.Series],
      dist2: Union[np.ndarray, pd.Series],
      margin_quantile_filter: float,
  ) -> float:
      """
      Calculate the Earth Movers Distance (Wasserstein distance).
  
      See https://en.wikipedia.org/wiki/Wasserstein_metric
  
      Function is for numerical data only.
  
      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.
      margin_quantile_filter: float
          float in range [0,0.5), representing which margins (high and low quantiles) of the distribution will be filtered
          out of the EMD calculation. This is done in order for extreme values not to affect the calculation
          disproportionally. This filter is applied to both distributions, in both margins.
      Returns
      -------
      Any
          the Wasserstein distance between the two distributions.
  
      Raises
      -------
      DeepchecksValueError
          if the value of margin_quantile_filter is not in range [0, 0.5)
  
      """
      if (
          not isinstance(margin_quantile_filter, Number)
          or margin_quantile_filter < 0
          or margin_quantile_filter >= 0.5
      ):
          raise DeepchecksValueError(
              f"margin_quantile_filter expected a value in range [0, 0.5), instead got {margin_quantile_filter}"
          )
  
      if margin_quantile_filter != 0:
          dist1 = filter_margins_by_quantile(
              dist1, margin_quantile_filter
          )
          dist2 = filter_margins_by_quantile(
              dist2, margin_quantile_filter
          )
  
      val_max = np.max([np.max(dist1), np.max(dist2)])
      val_min = np.min([np.min(dist1), np.min(dist2)])
  
      if val_max == val_min:
          return 0
  
      # Scale the distribution between 0 and 1:
      dist1 = (dist1 - val_min) / (val_max - val_min)
      dist2 = (dist2 - val_min) / (val_max - val_min)
  
      return wasserstein_distance(dist1, dist2)
  
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 8 for calling a global function with example usage: earth_movers_distance(dist1, dist2, margin_quantile_filter) and returns: wasserstein_distance, int