code: def test_plot_precision_recall_curve():
      """Tests ``plot_precision_recall_curve``."""
      # Creates fake data.
      precision = np.linspace(0, 1, num=25)
      recall = np.linspace(0, 0.5, num=25)
      pr_df = pd.DataFrame(
          {"precision": precision, "recall": recall, "key": 1}
      )
      groups_df = pd.DataFrame({"groups": ["A", "B", "C"], "key": 1})
      df = (
          pr_df.merge(groups_df, how="inner", on="key")
          .reset_index(drop=True)
          .drop("key", 1)
      )
      # Generates the precision recall curve.
      fig = plot_precision_recall_curve(
          df=df,
          grouping_col="groups",
          precision_col="precision",
          recall_col="recall",
      )
      # Asserts one curve per group.
      assert len(fig.data) == groups_df.shape[0]
      # Checks that the data is correct.
      for index, row in groups_df.iterrows():
          assert_equal(np.array(fig.data[index]["x"]), recall)
          assert_equal(np.array(fig.data[index]["y"]), precision)
          assert_equal(np.array(fig.data[index]["name"]), row["groups"])
  
      # Generates the precision recall curve when `grouping_col` is None.
      fig = plot_precision_recall_curve(
          df=pr_df,
          grouping_col=None,
          precision_col="precision",
          recall_col="recall",
      )
      # Asserts only one curve.
      assert len(fig.data) == 1
      # Checks that the data is correct.
      assert_equal(np.array(fig.data[0]["x"]), recall)
      assert_equal(np.array(fig.data[0]["y"]), precision)
  
      # Tests expected errors.
      expected_match = "must contain"
      with pytest.raises(ValueError, match=expected_match):
          plot_precision_recall_curve(
              df=df,
              grouping_col=None,
              precision_col="wrong_column",
              recall_col="recall",
          )
  
      expected_match = "must contain"
      with pytest.raises(ValueError, match=expected_match):
          plot_precision_recall_curve(
              df=df,
              grouping_col=None,
              precision_col="precision",
              recall_col="wrong_column",
          )
  
      expected_match = "is not found"
      with pytest.raises(ValueError, match=expected_match):
          plot_precision_recall_curve(
              df=df,
              grouping_col="wrong_column",
              precision_col="precision",
              recall_col="recall",
          )
  
imports: import numpy
  import pandas
  import pytest
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import START_TIME_COL
  from greykite.common.python_utils import assert_equal
  from greykite.common.viz.colors_utils import get_distinct_colors
  from greykite.common.viz.timeseries_annotate import add_multi_vrects
  from greykite.common.viz.timeseries_annotate import plot_anomalies_over_forecast_vs_actual
  from greykite.common.viz.timeseries_annotate import plot_event_periods_multi
  from greykite.common.viz.timeseries_annotate import plot_lines_markers
  from greykite.common.viz.timeseries_annotate import plot_overlay_anomalies_multi_metric
  from greykite.common.viz.timeseries_annotate import plot_precision_recall_curve
  from greykite.common.viz.timeseries_annotate import plt_annotate_series
  from greykite.common.viz.timeseries_annotate import plt_compare_series_annotations
label_desc: Use image node_id 9 for calling a global function with example usage: test_plot_precision_recall_curve() without return types