code: def test_idempotent_order_with_imbalanced_dataset(
      requests_mock: Mocker,
  ):
      pd.set_option("display.max_columns", 1000)
      url = "http://fake_url2"
  
      mock_default_requests(requests_mock, url)
  
      base_dir = os.path.dirname(os.path.realpath(__file__))
      train_path = os.path.join(
          base_dir, "test_data/binary/initial_train_imbalanced.parquet"
      )
      eval1_path = os.path.join(
          base_dir, "test_data/binary/initial_eval1_imbalanced.parquet"
      )
      eval2_path = os.path.join(
          base_dir, "test_data/binary/initial_eval2_imbalanced.parquet"
      )
      initial_train_df = pd.read_parquet(train_path)
  
      initial_eval1_df = pd.read_parquet(eval1_path)
      initial_eval2_df = pd.read_parquet(eval2_path)
  
      default_min_sample_threshold = Dataset.MIN_SAMPLE_THRESHOLD
      Dataset.MIN_SAMPLE_THRESHOLD = 7_000
  
      search_keys = {
          "phone_num": SearchKey.PHONE,
          "rep_date": SearchKey.DATE,
      }
      enricher = FeaturesEnricher(
          search_keys=search_keys,
          endpoint=url,
          api_key="fake_api_key",
          date_format="%Y-%m-%d",
          logs_enabled=False,
      )
  
      result_wrapper = DataFrameWrapper()
  
      def mocked_initial_search(
          self,
          trace_id,
          file_path,
          metadata,
          metrics,
          search_customization,
      ):
          result_wrapper.df = pd.read_parquet(file_path)
          raise TestException()
  
      original_initial_search = _RestClient.initial_search_v2
      _RestClient.initial_search_v2 = mocked_initial_search
  
      try:
          expected_result_path = os.path.join(
              os.path.dirname(os.path.realpath(__file__)),
              "test_data/binary/expected_prepared_imbalanced.parquet",
          )
  
          expected_result_df = (
              pd.read_parquet(expected_result_path)
              .sort_values(by="system_record_id")
              .reset_index(drop=True)
          )
  
          def test(n_shuffles: int):
              train_df = initial_train_df.copy()
              for _ in range(n_shuffles):
                  train_df = initial_train_df.sample(
                      frac=1
                  ).reset_index(drop=True)
              train_features = train_df.drop(columns="target")
              train_target = train_df["target"]
              eval1_df = initial_eval1_df.copy()
              for _ in range(n_shuffles):
                  eval1_df = eval1_df.sample(frac=1).reset_index(
                      drop=True
                  )
              eval1_features = eval1_df.drop(columns="target")
              eval1_target = eval1_df["target"]
              eval2_df = initial_eval2_df.copy()
              for _ in range(n_shuffles):
                  eval2_df = eval2_df.sample(frac=1).reset_index(
                      drop=True
                  )
              eval2_features = eval2_df.drop(columns="target")
              eval2_target = eval2_df["target"]
              eval_set = [
                  (eval1_features, eval1_target),
                  (eval2_features, eval2_target),
              ]
  
              try:
                  enricher.fit(
                      train_features,
                      train_target,
                      eval_set,
                      calculate_metrics=False,
                  )
              except TestException:
                  pass
  
              actual_result_df = result_wrapper.df.sort_values(
                  by="system_record_id"
              ).reset_index(drop=True)
  
              assert_frame_equal(actual_result_df, expected_result_df)
  
          for i in range(5):
              print(f"Run {i} iteration")
              test(i)
      finally:
          _RestClient.initial_search_v2 = original_initial_search
          Dataset.MIN_SAMPLE_THRESHOLD = default_min_sample_threshold
  
imports: import os
  from datetime import date
  from typing import List, Optional
  import numpy
  import pandas
  import pytest
  from pandas.testing import assert_frame_equal
  from requests_mock.mocker import Mocker
  from upgini import FeaturesEnricher, SearchKey
  from upgini.dataset import Dataset
  from upgini.errors import ValidationError
  from upgini.http import _RestClient
  from upgini.metadata import CVType, FeaturesMetadataV2, HitRateMetrics, ModelEvalSet, ModelTaskType, ProviderTaskMetadataV2, RuntimeParameters
  from upgini.resource_bundle import bundle
  from upgini.search_task import SearchTask
  from upgini.utils.datetime_utils import DateTimeSearchKeyConverter
  from .utils import mock_default_requests, mock_get_metadata, mock_get_task_metadata_v2, mock_initial_and_validation_summary, mock_initial_progress, mock_initial_search, mock_initial_summary, mock_raw_features, mock_validation_progress, mock_validation_raw_features, mock_validation_search, mock_validation_summary
label_desc: Use image node_id 25 for calling a global function with example usage: test_idempotent_order_with_imbalanced_dataset(requests_mock) without return types