code: def fetch_adult(
      features_drop: Optional[list] = None,
      return_X_y: bool = False,
      url_id: int = 0,
  ) -> Union[Bunch, Tuple[np.ndarray, np.ndarray]]:
      """
      Downloads and pre-processes 'adult' dataset.
      More info: http://mlr.cs.umass.edu/ml/machine-learning-databases/adult/
  
      Parameters
      ----------
      features_drop
          List of features to be dropped from dataset, by default drops ``["fnlwgt", "Education-Num"]``.
      return_X_y
          If ``True``, return features `X` and labels `y` as `numpy` arrays. If ``False`` return a `Bunch` object.
      url_id
          Index specifying which URL to use for downloading.
  
      Returns
      -------
      Bunch
          Dataset, labels, a list of features and a dictionary containing a list with the potential categories
          for each categorical feature where the key refers to the feature column.
      (data, target)
          Tuple if ``return_X_y=True``
      """
      if features_drop is None:
          features_drop = ["fnlwgt", "Education-Num"]
  
      # download data
      dataset_url = ADULT_URLS[url_id]
      raw_features = [
          "Age",
          "Workclass",
          "fnlwgt",
          "Education",
          "Education-Num",
          "Marital Status",
          "Occupation",
          "Relationship",
          "Race",
          "Sex",
          "Capital Gain",
          "Capital Loss",
          "Hours per week",
          "Country",
          "Target",
      ]
      try:
          resp = requests.get(dataset_url)
          resp.raise_for_status()
      except RequestException:
          logger.exception(
              "Could not connect, URL may be out of service"
          )
          raise
  
      raw_data = pd.read_csv(
          StringIO(resp.text),
          names=raw_features,
          delimiter=", ",
          engine="python",
      ).fillna("?")
  
      # get labels, features and drop unnecessary features
      labels = (raw_data["Target"] == ">50K").astype(int).values
      features_drop += ["Target"]
      data = raw_data.drop(features_drop, axis=1)
      features = list(data.columns)
  
      # map categorical features
      education_map = {
          "10th": "Dropout",
          "11th": "Dropout",
          "12th": "Dropout",
          "1st-4th": "Dropout",
          "5th-6th": "Dropout",
          "7th-8th": "Dropout",
          "9th": "Dropout",
          "Preschool": "Dropout",
          "HS-grad": "High School grad",
          "Some-college": "High School grad",
          "Masters": "Masters",
          "Prof-school": "Prof-School",
          "Assoc-acdm": "Associates",
          "Assoc-voc": "Associates",
      }
      occupation_map = {
          "Adm-clerical": "Admin",
          "Armed-Forces": "Military",
          "Craft-repair": "Blue-Collar",
          "Exec-managerial": "White-Collar",
          "Farming-fishing": "Blue-Collar",
          "Handlers-cleaners": "Blue-Collar",
          "Machine-op-inspct": "Blue-Collar",
          "Other-service": "Service",
          "Priv-house-serv": "Service",
          "Prof-specialty": "Professional",
          "Protective-serv": "Other",
          "Sales": "Sales",
          "Tech-support": "Other",
          "Transport-moving": "Blue-Collar",
      }
      country_map = {
          "Cambodia": "SE-Asia",
          "Canada": "British-Commonwealth",
          "China": "China",
          "Columbia": "South-America",
          "Cuba": "Other",
          "Dominican-Republic": "Latin-America",
          "Ecuador": "South-America",
          "El-Salvador": "South-America",
          "England": "British-Commonwealth",
          "France": "Euro_1",
          "Germany": "Euro_1",
          "Greece": "Euro_2",
          "Guatemala": "Latin-America",
          "Haiti": "Latin-America",
          "Holand-Netherlands": "Euro_1",
          "Honduras": "Latin-America",
          "Hong": "China",
          "Hungary": "Euro_2",
          "India": "British-Commonwealth",
          "Iran": "Other",
          "Ireland": "British-Commonwealth",
          "Italy": "Euro_1",
          "Jamaica": "Latin-America",
          "Japan": "Other",
          "Laos": "SE-Asia",
          "Mexico": "Latin-America",
          "Nicaragua": "Latin-America",
          "Outlying-US(Guam-USVI-etc)": "Latin-America",
          "Peru": "South-America",
          "Philippines": "SE-Asia",
          "Poland": "Euro_2",
          "Portugal": "Euro_2",
          "Puerto-Rico": "Latin-America",
          "Scotland": "British-Commonwealth",
          "South": "Euro_2",
          "Taiwan": "China",
          "Thailand": "SE-Asia",
          "Trinadad&Tobago": "Latin-America",
          "United-States": "United-States",
          "Vietnam": "SE-Asia",
      }
      married_map = {
          "Never-married": "Never-Married",
          "Married-AF-spouse": "Married",
          "Married-civ-spouse": "Married",
          "Married-spouse-absent": "Separated",
          "Separated": "Separated",
          "Divorced": "Separated",
          "Widowed": "Widowed",
      }
      mapping = {
          "Education": education_map,
          "Occupation": occupation_map,
          "Country": country_map,
          "Marital Status": married_map,
      }
  
      data_copy = data.copy()
      for f, f_map in mapping.items():
          data_tmp = data_copy[f].values
          for key, value in f_map.items():
              data_tmp[data_tmp == key] = value
          data[f] = data_tmp
  
      # get categorical features and apply labelencoding
      categorical_features = [
          f for f in features if data[f].dtype == "O"
      ]
      category_map = {}
      for f in categorical_features:
          le = LabelEncoder()
          data_tmp = le.fit_transform(data[f].values)
          data[f] = data_tmp
          category_map[features.index(f)] = list(le.classes_)
  
      # only return data values
      data = data.values
      target_names = ["<=50K", ">50K"]
  
      if return_X_y:
          return data, labels
  
      return Bunch(
          data=data,
          target=labels,
          feature_names=features,
          target_names=target_names,
          category_map=category_map,
      )
  
file_path: alibi/alibi/datasets/default.py
imports: import logging
  import pkgutil
  import tarfile
  import json
  from io import BytesIO, StringIO
  from typing import Optional, Tuple, Union, Dict
  import numpy
  import pandas
  import PIL
  import requests
  from requests import RequestException
  from sklearn.preprocessing import LabelEncoder
  from alibi.utils.data import Bunch
label_desc: Use image node_id 5 for calling a global function with example usage: fetch_adult(features_drop, return_X_y, url_id) and returns: Bunch, data,  labels