code: def test_calibrate_threshold_extreme():
      """Test that in the (rare) case where we should accept all points or
      reject all points, this is effectively what
      is done"""
  
      class MockBadPairsClassifier(
          MahalanobisMixin, _PairsClassifierMixin
      ):
          """A pairs classifier that returns bad scores (i.e. in the inverse order
          of what we would expect from a good pairs classifier
          """
  
          def fit(self, pairs, y, calibration_params=None):
              self.preprocessor_ = "not used"
              self.components_ = "not used"
              self.calibrate_threshold(
                  pairs,
                  y,
                  **(
                      calibration_params
                      if calibration_params is not None
                      else dict()
                  ),
              )
              return self
  
          def decision_function(self, pairs):
              return np.arange(pairs.shape[0], dtype=float)
  
      rng = np.random.RandomState(42)
      pairs = rng.randn(
          7, 2, 5
      )  # the info in X is not used, it's just for the
      # API
  
      y = [1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0]
      mock_clf = MockBadPairsClassifier()
      # case of bad scoring with more negative than positives. In
      # this case, when:
      # optimizing for accuracy we should reject all points
      mock_clf.fit(
          pairs, y, calibration_params={"strategy": "accuracy"}
      )
      assert_array_equal(mock_clf.predict(pairs), -np.ones(7))
  
      # optimizing for max_tpr we should accept all points if min_rate == 0. (
      # because by convention then tnr=0/0=0)
      mock_clf.fit(
          pairs,
          y,
          calibration_params={"strategy": "max_tpr", "min_rate": 0.0},
      )
      assert_array_equal(mock_clf.predict(pairs), np.ones(7))
      # optimizing for max_tnr we should reject all points if min_rate = 0. (
      # because by convention then tpr=0/0=0)
      mock_clf.fit(
          pairs,
          y,
          calibration_params={"strategy": "max_tnr", "min_rate": 0.0},
      )
      assert_array_equal(mock_clf.predict(pairs), -np.ones(7))
  
      y = [1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0]
      # case of bad scoring with more positives than negatives. In
      # this case, when:
      # optimizing for accuracy we should accept all points
      mock_clf.fit(
          pairs, y, calibration_params={"strategy": "accuracy"}
      )
      assert_array_equal(mock_clf.predict(pairs), np.ones(7))
      # optimizing for max_tpr we should accept all points if min_rate == 0. (
      # because by convention then tnr=0/0=0)
      mock_clf.fit(
          pairs,
          y,
          calibration_params={"strategy": "max_tpr", "min_rate": 0.0},
      )
      assert_array_equal(mock_clf.predict(pairs), np.ones(7))
      # optimizing for max_tnr we should reject all points if min_rate = 0. (
      # because by convention then tpr=0/0=0)
      mock_clf.fit(
          pairs,
          y,
          calibration_params={"strategy": "max_tnr", "min_rate": 0.0},
      )
      assert_array_equal(mock_clf.predict(pairs), -np.ones(7))
  
      # Note: we'll never find a case where we would reject all points for
      # maximizing tpr (we can always accept more points), and accept all
      # points for maximizing tnr (we can always reject more points)
  
      # case of alternated scores: for optimizing the f_1 score we should accept
      # all points (because this way we have max recall (1) and max precision (
      # here: 0.5))
      y = [1.0, -1.0, 1.0, -1.0, 1.0, -1.0]
      mock_clf.fit(
          pairs[:6],
          y,
          calibration_params={"strategy": "f_beta", "beta": 1.0},
      )
      assert_array_equal(mock_clf.predict(pairs[:6]), np.ones(6))
  
imports: from functools import partial
  import pytest
  from numpy.testing import assert_array_equal
  from scipy.spatial.distance import euclidean
  from metric_learn.base_metric import _PairsClassifierMixin, MahalanobisMixin
  from sklearn.exceptions import NotFittedError
  from sklearn.metrics import f1_score, accuracy_score, fbeta_score, precision_score
  from sklearn.model_selection import train_test_split
  from test.test_utils import pairs_learners, ids_pairs_learners
  from metric_learn.sklearn_shims import set_random_state
  from sklearn import clone
  import numpy
  from itertools import product
label_desc: Use image node_id 17 for calling a global function with example usage: test_calibrate_threshold_extreme() and returns: self, np