# Buggy code
def plot_precision_recall_curve(
    estimator,
    X,
    y,
    sample_weight=None,
    response_method="auto",
    name=None,
    ax=None,
    **kwargs,
):
    """Plot Precision Recall Curve for binary classifers.

    Extra keyword arguments will be passed to matplotlib's `plot`.

    Read more in the :ref:`User Guide <precision_recall_f_measure_metrics>`.

    Parameters
    ----------
    estimator : estimator instance
        Trained classifier.

    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Input values.

    y : array-like of shape (n_samples,)
        Binary target values.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    response_method : {'predict_proba', 'decision_function', 'auto'}, \
                      default='auto'
        Specifies whether to use :term:`predict_proba` or
        :term:`decision_function` as the target response. If set to 'auto',
        :term:`predict_proba` is tried first and if it does not exist
        :term:`decision_function` is tried next.

    name : str, default=None
        Name for labeling curve. If `None`, the name of the
        estimator is used.

    ax : matplotlib axes, default=None
        Axes object to plot on. If `None`, a new figure and axes is created.

    **kwargs : dict
        Keyword arguments to be passed to matplotlib's `plot`.

    Returns
    -------
    display : :class:`~sklearn.metrics.PrecisionRecallDisplay`
        Object that stores computed values.
    """
    check_matplotlib_support("plot_precision_recall_curve")

    classification_error = "{} should be a binary classifer".format(
        estimator.__class__.__name__
    )
    if not is_classifier(estimator):
        raise ValueError(classification_error)

    prediction_method = _check_classifer_response_method(estimator, response_method)
    y_pred = prediction_method(X)

    if y_pred.ndim != 1:
        if y_pred.shape[1] != 2:
            raise ValueError(classification_error)
        else:
            y_pred = y_pred[:, 1]

    pos_label = estimator.classes_[1]
    precision, recall, _ = precision_recall_curve(
        y, y_pred, pos_label=pos_label, sample_weight=sample_weight
    )
    average_precision = average_precision_score(y, y_pred, sample_weight=sample_weight)
    viz = PrecisionRecallDisplay(
        precision, recall, average_precision, estimator.__class__.__name__
    )
    return viz.plot(ax=ax, name=name, **kwargs)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/tmp.py in <module>
33 model.fit(X_train, y_train)
34 plot_precision_recall_curve(
---> 35     model, X_test, y_test
36 )

~/Documents/packages/scikit-learn/sklearn/metrics/_plot/precision_recall_curve.py in plot_precision_recall_curve(estimator, X, y, sample_weight, response_method, name, ax, **kwargs)
163                                                   sample_weight=sample_weight)
164     average_precision = average_precision_score(y, y_pred,
--> 165                                                 sample_weight=sample_weight)
166     viz = PrecisionRecallDisplay(precision, recall, average_precision,
167                                  estimator.__class__.__name__)

~/Documents/packages/scikit-learn/sklearn/metrics/_ranking.py in average_precision_score(y_true, y_score, average, pos_label, sample_weight)
209         if len(present_labels) == 2 and pos_label not in present_labels:
210             raise ValueError("pos_label=%r is invalid. Set it to a label in "
--> 211                              "y_true." % pos_label)
212     average_precision = partial(_binary_uninterpolated_average_precision,
213                                 pos_label=pos_label)

ValueError: pos_label=1 is invalid. Set it to a label in y_true.

# Fixed code
def plot_precision_recall_curve(
    estimator,
    X,
    y,
    sample_weight=None,
    response_method="auto",
    name=None,
    ax=None,
    **kwargs,
):
    """Plot Precision Recall Curve for binary classifers.

    Extra keyword arguments will be passed to matplotlib's `plot`.

    Read more in the :ref:`User Guide <precision_recall_f_measure_metrics>`.

    Parameters
    ----------
    estimator : estimator instance
        Trained classifier.

    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Input values.

    y : array-like of shape (n_samples,)
        Binary target values.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    response_method : {'predict_proba', 'decision_function', 'auto'}, \
                      default='auto'
        Specifies whether to use :term:`predict_proba` or
        :term:`decision_function` as the target response. If set to 'auto',
        :term:`predict_proba` is tried first and if it does not exist
        :term:`decision_function` is tried next.

    name : str, default=None
        Name for labeling curve. If `None`, the name of the
        estimator is used.

    ax : matplotlib axes, default=None
        Axes object to plot on. If `None`, a new figure and axes is created.

    **kwargs : dict
        Keyword arguments to be passed to matplotlib's `plot`.

    Returns
    -------
    display : :class:`~sklearn.metrics.PrecisionRecallDisplay`
        Object that stores computed values.
    """
    check_matplotlib_support("plot_precision_recall_curve")

    classification_error = "{} should be a binary classifer".format(
        estimator.__class__.__name__
    )
    if not is_classifier(estimator):
        raise ValueError(classification_error)

    prediction_method = _check_classifer_response_method(estimator, response_method)
    y_pred = prediction_method(X)

    if y_pred.ndim != 1:
        if y_pred.shape[1] != 2:
            raise ValueError(classification_error)
        else:
            y_pred = y_pred[:, 1]

    pos_label = estimator.classes_[1]
    precision, recall, _ = precision_recall_curve(
        y, y_pred, pos_label=pos_label, sample_weight=sample_weight
    )
    average_precision = average_precision_score(
        y, y_pred, pos_label=pos_label, sample_weight=sample_weight
    )
    viz = PrecisionRecallDisplay(
        precision, recall, average_precision, estimator.__class__.__name__
    )
    return viz.plot(ax=ax, name=name, **kwargs)