code: def test_optimize_df_with_constraints():
      """Tests `optimize_df_with_constraints`."""
      df = pd.DataFrame(
          {
              "a": [20, 20, 5, 10, 10, 0, 5],
              "b": [1, 1, 2, 2, 3, 3, 4],
              "c": [1, 2, 3, 4, 5, 6, 7],
          }
      )
      # Constraint is satisfied, unique optimal
      with LogCapture(LOGGER_NAME) as log_capture:
          optimal_dict = optimize_df_with_constraints(
              df=df,
              objective_col="a",
              constraint_col="b",
              constraint_value=4,
          )
          expected_optimal_dict = {"a": 5, "b": 4, "c": 7}
          assert_equal(optimal_dict, expected_optimal_dict)
          log_capture.check(
              (
                  LOGGER_NAME,
                  "INFO",
                  f"Values satisfying the constraint are found.\n"
                  f"Solving the following optimization problem:\n"
                  f"Maximize a subject to b >= 4.",
              )
          )
      # Constraint is satisfied. Multiple rows with the maximum value
      # in ``objective_col``, resolved by considering ``constraint_col``
      optimal_dict = optimize_df_with_constraints(
          df=df,
          objective_col="a",
          constraint_col="b",
          constraint_value=2,
      )
      expected_optimal_dict = {"a": 10, "b": 3, "c": 5}
      assert_equal(optimal_dict, expected_optimal_dict)
      # Constraint is satisfied. Multiple rows with the maximum value
      # in both ``objective_col`` and ``constraint_col``, last entry is chosen
      optimal_dict = optimize_df_with_constraints(
          df=df,
          objective_col="a",
          constraint_col="b",
          constraint_value=1,
      )
      expected_optimal_dict = {"a": 20, "b": 1, "c": 2}
      assert_equal(optimal_dict, expected_optimal_dict)
  
      # Constraint is NOT satisfied, unique optimal
      with LogCapture(LOGGER_NAME) as log_capture:
          optimal_dict = optimize_df_with_constraints(
              df=df,
              objective_col="a",
              constraint_col="b",
              constraint_value=4.5,
          )
          expected_optimal_dict = {"a": 5, "b": 4, "c": 7}
          assert_equal(optimal_dict, expected_optimal_dict)
          log_capture.check(
              (
                  LOGGER_NAME,
                  "INFO",
                  f"No values satisfy the constraint.\n"
                  f"Maximizing ``constraint_col`` (b) so that it is as "
                  f"close as possible to the ``constraint_value`` (4.5).",
              )
          )
      # Constraint is NOT satisfied. Multiple rows with the maximum value
      # in ``objective_col``, resolved by considering ``constraint_col``
      df = df[:6]
      optimal_dict = optimize_df_with_constraints(
          df=df,
          objective_col="a",
          constraint_col="b",
          constraint_value=3.5,
      )
      expected_optimal_dict = {"a": 10, "b": 3, "c": 5}
      assert_equal(optimal_dict, expected_optimal_dict)
      # Constraint is NOT satisfied. Multiple rows with the maximum value
      # in both ``objective_col`` and ``constraint_col``, last entry is chosen
      df = df[:2]
      optimal_dict = optimize_df_with_constraints(
          df=df,
          objective_col="a",
          constraint_col="b",
          constraint_value=1.5,
      )
      expected_optimal_dict = {"a": 20, "b": 1, "c": 2}
      assert_equal(optimal_dict, expected_optimal_dict)
  
imports: import itertools
  import numpy
  import pandas
  import pytest
  from testfixtures import LogCapture
  from greykite.common.constants import ANOMALY_COL
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import LOGGER_NAME
  from greykite.common.constants import START_TIME_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.testing_utils import assert_equal
  from greykite.detection.detector.ad_utils import add_new_params_to_records
  from greykite.detection.detector.ad_utils import get_anomaly_df
  from greykite.detection.detector.ad_utils import get_anomaly_df_from_outliers
  from greykite.detection.detector.ad_utils import get_canonical_anomaly_df
  from greykite.detection.detector.ad_utils import get_timestamp_ceil
  from greykite.detection.detector.ad_utils import get_timestamp_floor
  from greykite.detection.detector.ad_utils import optimize_df_with_constraints
  from greykite.detection.detector.ad_utils import partial_return
  from greykite.detection.detector.ad_utils import validate_volatility_features
  from greykite.detection.detector.ad_utils import vertical_concat_dfs
label_desc: Use image node_id 7 for calling a global function with example usage: test_optimize_df_with_constraints() without return types