code: def _fairlearn_binary(preds, target, groups, ignore_index):
      metrics = {"dp": selection_rate, "eo": true_positive_rate}
  
      preds = preds.numpy()
      target = target.numpy()
      groups = groups.numpy()
  
      if np.issubdtype(preds.dtype, np.floating):
          if not ((preds > 0) & (preds < 1)).all():
              preds = sigmoid(preds)
          preds = (preds >= THRESHOLD).astype(np.uint8)
  
      target, preds, groups = remove_ignore_index_groups(
          target, preds, groups, ignore_index
      )
  
      mf = MetricFrame(
          metrics=metrics,
          y_true=target,
          y_pred=preds,
          sensitive_features=groups,
      )
  
      mf_group = mf.by_group
      ratios = mf.ratio()
  
      return {
          f"DP_{pd.to_numeric(mf_group['dp']).idxmin()}_{pd.to_numeric(mf_group['dp']).idxmax()}": torch.tensor(
              ratios["dp"], dtype=torch.float
          ),
          f"EO_{pd.to_numeric(mf_group['eo']).idxmin()}_{pd.to_numeric(mf_group['eo']).idxmax()}": torch.tensor(
              ratios["eo"], dtype=torch.float
          ),
      }
  
imports: import inspect
  from functools import partial
  from typing import Any, Callable, Dict, Optional
  from unittest import mock
  import numpy
  import pandas
  import pytest
  import torch
  from fairlearn.metrics import MetricFrame, selection_rate, true_positive_rate
  from scipy.special import expit
  from torch import Tensor
  from torchmetrics import Metric
  from torchmetrics.classification.group_fairness import BinaryFairness
  from torchmetrics.functional.classification.group_fairness import binary_fairness
  from torchmetrics.utilities.imports import _PYTHON_LOWER_3_8
  from unittests import THRESHOLD
  from unittests.classification.inputs import _group_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, _assert_dtype_support, inject_ignore_index, remove_ignore_index_groups
  from unittests.helpers.testers import _assert_allclose
  from unittests.helpers.testers import _assert_requires_grad
  from unittests.helpers.testers import _assert_tensor
label_desc: Use image node_id 1 for calling a global function with example usage: _fairlearn_binary(preds, target, groups, ignore_index) and returns: dict