code: def test_direct_features_of_multi_output_agg_primitives(pd_es):
      class ThreeMostCommonCat(AggregationPrimitive):
          name = "n_most_common_categorical"
          input_types = [ColumnSchema(semantic_tags={"category"})]
          return_type = ColumnSchema(semantic_tags={"category"})
          number_output_features = 3
  
          def get_function(self, agg_type="pandas"):
              def pd_top3(x):
                  counts = x.value_counts()
                  counts = counts[counts > 0]
                  array = np.array(counts.index[:3])
                  if len(array) < 3:
                      filler = np.full(3 - len(array), np.nan)
                      array = np.append(array, filler)
                  return array
  
              return pd_top3
  
      fm, fl = dfs(
          entityset=pd_es,
          target_dataframe_name="log",
          agg_primitives=[ThreeMostCommonCat],
          trans_primitives=[],
          max_depth=3,
      )
  
      has_nmost_as_base = []
      for feature in fl:
          is_base = False
          if len(feature.base_features) > 0 and isinstance(
              feature.base_features[0].primitive,
              ThreeMostCommonCat,
          ):
              is_base = True
          has_nmost_as_base.append(is_base)
      assert any(has_nmost_as_base)
  
      true_result_rows = []
      session_data = {
          0: ["coke zero", "car", np.nan],
          1: ["toothpaste", "brown bag", np.nan],
          2: ["brown bag", np.nan, np.nan],
          3: set(
              ["Haribo sugar-free gummy bears", "coke zero", np.nan]
          ),
          4: ["coke zero", np.nan, np.nan],
          5: ["taco clock", np.nan, np.nan],
      }
      for i, count in enumerate([5, 4, 1, 2, 3, 2]):
          while count > 0:
              true_result_rows.append(session_data[i])
              count -= 1
  
      tempname = (
          "sessions.N_MOST_COMMON_CATEGORICAL(log.product_id)[%s]"
      )
      for i, row in enumerate(true_result_rows):
          for j in range(3):
              value = fm[tempname % (j)][i]
              if isinstance(row, set):
                  assert pd.isnull(value) or value in row
              else:
                  assert (
                      pd.isnull(value) and pd.isnull(row[j])
                  ) or value == row[j]
  
imports: import numpy
  import pandas
  import pytest
  from woodwork.column_schema import ColumnSchema
  from woodwork.logical_types import Datetime
  from featuretools.computational_backends.feature_set import FeatureSet
  from featuretools.computational_backends.feature_set_calculator import FeatureSetCalculator
  from featuretools.feature_base import DirectFeature, Feature, IdentityFeature
  from featuretools.primitives import AggregationPrimitive, Day, Hour, Minute, Month, NMostCommon, Second, TransformPrimitive, Year
  from featuretools.primitives.utils import PrimitivesDeserializer
  from featuretools.synthesis import dfs
  from featuretools.tests.testing_utils import to_pandas
  from featuretools.utils.gen_utils import Library
label_desc: Use image node_id 7 for calling a global function with example usage: test_direct_features_of_multi_output_agg_primitives(pd_es) and returns: pd_top3, array