code: def test_components_is_2D(estimator, build_dataset):
      """Tests that the transformation matrix of metric learners is 2D"""
      input_data, labels, _, X = build_dataset()
      model = clone(estimator)
      set_random_state(model)
      # test that it works for X.shape[1] features
      model.fit(*remove_y(estimator, input_data, labels))
      assert model.components_.shape == (X.shape[1], X.shape[1])
  
      if isinstance(estimator, _BaseSDML):
          # SDML doesn't support running on a single feature.
          return
  
      # test that it works for 1 feature. Use 2nd dimension, to avoid border cases
      trunc_data = input_data[..., 1:2]
      # we drop duplicates that might have been formed, i.e. of the form
      # aabc or abcc or aabb for quadruplets, and aa for pairs.
  
      if isinstance(estimator, _QuadrupletsClassifierMixin):
          pairs_idx = [[0, 1], [2, 3]]
      elif isinstance(estimator, _TripletsClassifierMixin):
          pairs_idx = [[0, 1], [0, 2]]
      elif isinstance(estimator, _PairsClassifierMixin):
          pairs_idx = [[0, 1]]
      else:
          pairs_idx = []
  
      for pair_idx in pairs_idx:
          pairs = trunc_data[:, pair_idx, :]
          diffs = pairs[:, 1, :] - pairs[:, 0, :]
          to_keep = np.abs(diffs.ravel()) > 1e-9
          trunc_data = trunc_data[to_keep]
          labels = labels[to_keep]
  
      model.fit(*remove_y(estimator, trunc_data, labels))
      assert model.components_.shape == (1, 1)
  
imports: from itertools import product
  import pytest
  import numpy
  from numpy.linalg import LinAlgError
  from numpy.testing import assert_array_almost_equal, assert_allclose, assert_array_equal
  from scipy.spatial.distance import pdist, squareform, mahalanobis
  from scipy.stats import ortho_group
  from sklearn import clone
  from sklearn.cluster import DBSCAN
  from sklearn.datasets import make_spd_matrix, make_blobs
  from sklearn.utils import check_random_state, shuffle
  from sklearn.utils.multiclass import type_of_target
  from metric_learn.sklearn_shims import set_random_state
  from metric_learn._util import make_context, _initialize_metric_mahalanobis
  from metric_learn.sdml import _BaseSDML
  from metric_learn.base_metric import _QuadrupletsClassifierMixin, _TripletsClassifierMixin, _PairsClassifierMixin
  from metric_learn.exceptions import NonPSDError
  from test.test_utils import ids_metric_learners, metric_learners, remove_y, ids_classifiers
label_desc: Use image node_id 15 for calling a global function with example usage: test_components_is_2D(estimator, build_dataset) without return types