class_docstr: Converts pandas categoricals to numpy int in preparation for OHE.
  
  Parameters
  ----------
  max_levels : int
      The maximum number of unique values for OHE. Selected categories are based on frequency.
  fillna_val : int, default = None
      The default value to fill NaN.
      If None, automatically inferred as a new value not present in existing categories.
  infrequent_val : int or {'na', 'na+1}, default = 'na'
      The value to group all infrequent categories to (those that aren't within the max_levels most frequent categories).
      If 'na', uses `fillna_val`.
      If 'na+1', uses `fillna_val+1`. This guarantees a new category for infrequent values separate from missing values if `fillna_val=None`.
class_docstr_tok: ["Converts","pandas","categoricals","to","numpy","int","in","preparation","for","OHE",".","Parameters","--","--","--","--","--","max_levels",":","int","The","maximum","number","of","unique","values","for","OHE",".","Selected","categories","are","based","on","frequency",".","fillna_val",":","int",",","default","=","None","The","default","value","to","fill","NaN",".","If","None",",","automatically","inferred","as","a","new","value","not","present","in","existing","categories",".","infrequent_val",":","int","or","{","'na","'",",","'na+1","}",",","default","=","'na'","The","value","to","group","all","infrequent","categories","to","(","those","that","are","n't","within","the","max_levels","most","frequent","categories",")",".","If","'na","'",",","uses","`","fillna_val","`",".","If","'na+1","'",",","uses","`","fillna_val+1","`",".","This","guarantees","a","new","category","for","infrequent","values","separate","from","missing","values","if","`","fillna_val=None","`","."]
code: def fit(self, X: DataFrame):
      # dtype_buffer=2 is required to avoid edge case errors with invalid self.infrequent_val in 'na+1' mode.
      self._dtype, fillna_val = self._get_dtype_and_fillna(
          X, dtype_buffer=2
      )
      if self.fillna_val is None:
          self.fillna_val = fillna_val
      if self.infrequent_val == "na":
          self.infrequent_val = self.fillna_val
      elif self.infrequent_val == "na+1":
          self.infrequent_val = self.fillna_val + 1
  
      X = self.pd_to_np(X)
      self.num_cols = X.shape[1]
      for col in range(self.num_cols):
          data = X[:, col]
          uniques, counts = np.unique(data, return_counts=True)
          self.cats[col] = uniques[
              np.argsort(counts)[-self.max_levels :]
          ]
          with warnings.catch_warnings():
              # Refer to https://stackoverflow.com/questions/40659212/futurewarning-elementwise-comparison-failed-returning-scalar-but-in-the-futur
              warnings.simplefilter(
                  action="ignore", category=FutureWarning
              )
              if (
                  self.infrequent_val in self.cats[col]
                  or str(self.infrequent_val) in self.cats[col]
              ):
                  # Add one extra level since NaN values shouldn't be counted towards max levels
                  self.cats[col] = uniques[
                      np.argsort(counts)[-(self.max_levels + 1) :]
                  ]
  
imports: import logging
  import warnings
  import numpy
  import pandas
  from pandas import DataFrame
  from sklearn.preprocessing import OneHotEncoder
  from autogluon.common.features.types import R_CATEGORY, R_INT, S_BOOL, S_SPARSE
  from .abstract import AbstractFeatureGenerator
label_desc: Use image node_id 2 for calling the CatToInt obj's underlying member method code with example usage: obj.fit(X) without return types