code: def fetch_nab(
      ts: str, return_X_y: bool = False
  ) -> Union[Bunch, Tuple[pd.DataFrame, pd.DataFrame]]:
      """
      Get time series in a DataFrame from the Numenta Anomaly Benchmark: https://github.com/numenta/NAB.
  
      Parameters
      ----------
      ts
  
      return_X_y
          Bool, whether to only return the data and target values or a Bunch object.
  
      Returns
      -------
      Bunch
          Dataset and outlier labels (0 means 'normal' and 1 means 'outlier') in DataFrames with timestamps.
      (data, target)
          Tuple if 'return_X_y' equals True.
      """
      url_labels = "https://raw.githubusercontent.com/numenta/NAB/master/labels/combined_labels.json"
      try:
          resp = requests.get(url_labels, timeout=TIMEOUT)
          resp.raise_for_status()
      except RequestException:
          logger.exception(
              "Could not connect, URL may be out of service"
          )
          raise
      labels_json = resp.json()
      outliers = labels_json[ts + ".csv"]
      if not outliers:
          logger.warning("The dataset does not contain any outliers.")
      url = (
          "https://raw.githubusercontent.com/numenta/NAB/master/data/"
          + ts
          + ".csv"
      )
      df = pd.read_csv(url, header=0, index_col=0)
      labels = np.zeros(df.shape[0])
      for outlier in outliers:
          outlier_id = np.where(df.index == outlier)[0][0]
          labels[outlier_id] = 1
      df.index = pd.to_datetime(df.index)
      df_labels = pd.DataFrame(
          data={"is_outlier": labels}, index=df.index
      )
  
      if return_X_y:
          return df, df_labels
  
      return Bunch(
          data=df, target=df_labels, target_names=["normal", "outlier"]
      )
  
imports: import io
  import logging
  from io import BytesIO
  from typing import List, Tuple, Type, Union
  from xml.etree import ElementTree
  import dill
  import numpy
  import pandas
  import requests
  from alibi_detect.utils.data import Bunch
  from alibi_detect.utils.url import _join_url
  from requests import RequestException
  from urllib.error import URLError
  from scipy.io import arff
  from sklearn.datasets import fetch_kddcup99
label_desc: Use image node_id 8 for calling a global function with example usage: fetch_nab(ts, return_X_y) and returns: Bunch, df,  df_labels