code: def test_make_three_most_common(pd_es):
      class NMostCommoner(AggregationPrimitive):
          name = "pd_top3"
          input_types = ([ColumnSchema(semantic_tags={"category"})],)
          return_type = None
          number_output_features = 3
  
          def get_function(self):
              def pd_top3(x):
                  counts = x.value_counts()
                  counts = counts[counts > 0]
                  array = np.array(counts[:3].index)
                  if len(array) < 3:
                      filler = np.full(3 - len(array), np.nan)
                      array = np.append(array, filler)
                  return array
  
              return pd_top3
  
      fm, features = dfs(
          entityset=pd_es,
          target_dataframe_name="customers",
          instance_ids=[0, 1, 2],
          agg_primitives=[NMostCommoner],
          trans_primitives=[],
      )
  
      df = fm[["PD_TOP3(log.product_id)[%s]" % i for i in range(3)]]
  
      assert set(df.iloc[0].values[:2]) == set(
          ["coke zero", "toothpaste"],
      )  # coke zero and toothpaste have same number of occurrences
      assert df.iloc[0].values[2] in [
          "car",
          "brown bag",
      ]  # so just check that the top two match
  
      assert (
          df.iloc[1]
          .reset_index(drop=True)
          .equals(
              pd.Series(
                  ["coke zero", "Haribo sugar-free gummy bears", np.nan]
              )
          )
      )
      assert (
          df.iloc[2]
          .reset_index(drop=True)
          .equals(pd.Series(["taco clock", np.nan, np.nan]))
      )
  
imports: from datetime import datetime
  from inspect import isclass
  from math import isnan
  import numpy
  import pandas
  import pytest
  from woodwork.column_schema import ColumnSchema
  from woodwork.logical_types import Datetime
  from featuretools import AggregationFeature, Feature, IdentityFeature, Timedelta, calculate_feature_matrix, dfs, primitives
  from featuretools.entityset.relationship import RelationshipPath
  from featuretools.feature_base.cache import feature_cache
  from featuretools.primitives import Count, Max, Mean, Median, NMostCommon, NumTrue, NumUnique, Sum, TimeSinceFirst, TimeSinceLast, get_aggregation_primitives
  from featuretools.primitives.base import AggregationPrimitive
  from featuretools.synthesis.deep_feature_synthesis import DeepFeatureSynthesis, match
  from featuretools.tests.testing_utils import backward_path, feature_with_name, to_pandas
  from featuretools.utils.gen_utils import Library
label_desc: Use image node_id 23 for calling a global function with example usage: test_make_three_most_common(pd_es) and returns: pd_top3, array