def _booster_feature_names_workaround(model, feature_names):
    """
    Removes booster feature names. This is intended as a workaround for faulty JSON dump
    generated by get_dump(dump_format='json') and dump_model(..., dump_format='json')
    methods in XGBoost.

    Parameters
    ----------
    model: Booster or XGBRegressor or XGBClassifier
        model from which feature names are to be removed
    feature_names: list
        list of feature names

    Returns
    -------
    Booster or XGBRegressor or XGBClassifier
        a copy of a model with removed feature names

    """

    # make sure feature names are not None
    assert feature_names is not None

    if isinstance(model, _xgboost.core.Booster):
        # if feature names are already nulled return booster
        if model.feature_names is None:
            return model

        # copy booster to avoid modifying the original
        model_copy = model.copy()

        # make sure feature names match
        _np.testing.assert_array_equal(model.feature_names, feature_names), \
            ValueError('`feature_names` param does not match booster feature names')

        # Remove feature names from the booster
        model_copy.feature_names = None
    elif isinstance(model, (_xgboost.XGBRegressor, _xgboost.XGBClassifier)):
        # if feature names are already nulled return booster
        if model.get_booster().feature_names is None:
            return model

        # copy estimator with deepcopy to get identical object without modifying the original
        model_copy = deepcopy(model)

        # make sure feature names match
        _np.testing.assert_array_equal(model.get_booster().feature_names, feature_names), \
            ValueError('`feature_names` param does not match booster feature names')

        # Remove feature names from the sklearn wrapper
        model_copy.get_booster().feature_names = None
    else:
        raise TypeError(f"Invalid model object type: {type(model)}")
    return model_copy

    Removes booster feature names. This is intended as a workaround for faulty JSON dump
    generated by get_dump(dump_format='json') and dump_model(..., dump_format='json')
    methods in XGBoost.

    Parameters
    ----------
    model: Booster or XGBRegressor or XGBClassifier
        model from which feature names are to be removed
    feature_names: list
        list of feature names

    Returns
    -------
    Booster or XGBRegressor or XGBClassifier
        a copy of a model with removed feature names

    
coremltools/converters/xgboost/_tree_ensemble.py