def METHOD_NAME(self, X, fit=False):
    """Encodes each categorical feature using ordinal encoding."""
    X = infer_feature_types(X)
    cat_cols = list(X.ww.select("category", return_schema=True).columns)
    if fit:
        self.input_feature_names = list(X.columns)
    X_encoded = _rename_column_names_to_numeric(X)
    rename_cols_dict = dict(zip(X.columns, X_encoded.columns))
    cat_cols = [rename_cols_dict[col] for col in cat_cols]
    if len(cat_cols) == 0:
        return X_encoded
    if fit:
        self._ordinal_encoder = OrdinalEncoder()
        encoder_output = self._ordinal_encoder.fit_transform(X_encoded[cat_cols])
    else:
        encoder_output = self._ordinal_encoder.transform(X_encoded[cat_cols])
    X_encoded[cat_cols] = pd.DataFrame(encoder_output)
    X_encoded[cat_cols] = X_encoded[cat_cols].astype("category")
    return X_encoded