class_docstr: Base class for all structured datasets.
  
  A StructuredDataset requires data to be stored in :obj:`numpy.ndarray`
  objects with :obj:`~numpy.dtype` as :obj:`~numpy.float64`.
  
  Attributes:
      features (numpy.ndarray): Dataset features for each instance.
      labels (numpy.ndarray): Generic label corresponding to each instance
          (could be ground-truth, predicted, cluster assignments, etc.).
      scores (numpy.ndarray): Probability score associated with each label.
          Same shape as `labels`. Only valid for binary labels (this includes
          one-hot categorical labels as well).
      protected_attributes (numpy.ndarray): A subset of `features` for which
          fairness is desired.
      feature_names (list(str)): Names describing each dataset feature.
      label_names (list(str)): Names describing each label.
      protected_attribute_names (list(str)): A subset of `feature_names`
          corresponding to `protected_attributes`.
      privileged_protected_attributes (list(numpy.ndarray)): A subset of
          protected attribute values which are considered privileged from a
          fairness perspective.
      unprivileged_protected_attributes (list(numpy.ndarray)): The remaining
          possible protected attribute values which are not included in
          `privileged_protected_attributes`.
      instance_names (list(str)): Indentifiers for each instance. Sequential
          integers by default.
      instance_weights (numpy.ndarray):  Weighting for each instance. All
          equal (ones) by default. Pursuant to standard practice in social
          science data, 1 means one person or entity. These weights are hence
          person or entity multipliers (see:
          https://www.ibm.com/support/knowledgecenter/en/SS3RA7_15.0.0/com.ibm.spss.modeler.help/netezza_decisiontrees_weights.htm)
          These weights *may not* be normalized to sum to 1 across the entire
          dataset, rather the nominal (default) weight of each entity/record
          in the data is 1. This is similar in spirit to the person weight in
          census microdata samples.
          https://www.census.gov/programs-surveys/acs/technical-documentation/pums/about.html
      ignore_fields (set(str)): Attribute names to ignore when doing equality
          comparisons. Always at least contains `'metadata'`.
      metadata (dict): Details about the creation of this dataset. For
          example::
  
              {
                  'transformer': 'Dataset.__init__',
                  'params': kwargs,
                  'previous': None
              }
class_docstr_tok: ["Base","class","for","all","structured","datasets",".","A","StructuredDataset","requires","data","to","be","stored","in",":","obj",":","`","numpy.ndarray","`","objects","with",":","obj",":","`","~numpy.dtype","`","as",":","obj",":","`","~numpy.float64","`",".","Attributes",":","features","(","numpy.ndarray",")",":","Dataset","features","for","each","instance",".","labels","(","numpy.ndarray",")",":","Generic","label","corresponding","to","each","instance","(","could","be","ground-truth",",","predicted",",","cluster","assignments",",","etc.",")",".","scores","(","numpy.ndarray",")",":","Probability","score","associated","with","each","label",".","Same","shape","as","`","labels","`",".","Only","valid","for","binary","labels","(","this","includes","one-hot","categorical","labels","as","well",")",".","protected_attributes","(","numpy.ndarray",")",":","A","subset","of","`","features","`","for","which","fairness","is","desired",".","feature_names","(","list","(","str",")",")",":","Names","describing","each","dataset","feature",".","label_names","(","list","(","str",")",")",":","Names","describing","each","label",".","protected_attribute_names","(","list","(","str",")",")",":","A","subset","of","`","feature_names","`","corresponding","to","`","protected_attributes","`",".","privileged_protected_attributes","(","list","(","numpy.ndarray",")",")",":","A","subset","of","protected","attribute","values","which","are","considered","privileged","from","a","fairness","perspective",".","unprivileged_protected_attributes","(","list","(","numpy.ndarray",")",")",":","The","remaining","possible","protected","attribute","values","which","are","not","included","in","`","privileged_protected_attributes","`",".","instance_names","(","list","(","str",")",")",":","Indentifiers","for","each","instance",".","Sequential","integers","by","default",".","instance_weights","(","numpy.ndarray",")",":","Weighting","for","each","instance",".","All","equal","(","ones",")","by","default",".","Pursuant","to","standard","practice","in","social","science","data",",","1","means","one","person","or","entity",".","These","weights","are","hence","person","or","entity","multipliers","(","see",":","https",":","\/\/www.ibm.com\/support\/knowledgecenter\/en\/SS3RA7_15.0.0\/com.ibm.spss.modeler.help\/netezza_decisiontrees_weights.htm",")","These","weights","*","may","not","*","be","normalized","to","sum","to","1","across","the","entire","dataset",",","rather","the","nominal","(","default",")","weight","of","each","entity\/record","in","the","data","is","1",".","This","is","similar","in","spirit","to","the","person","weight","in","census","microdata","samples",".","https",":","\/\/www.census.gov\/programs-surveys\/acs\/technical-documentation\/pums\/about.html","ignore_fields","(","set","(","str",")",")",":","Attribute","names","to","ignore","when","doing","equality","comparisons",".","Always","at","least","contains","`","'metadata","'","`",".","metadata","(","dict",")",":","Details","about","the","creation","of","this","dataset",".","For","example",":",":","{","'transformer","'",":","'Dataset.__init__","'",",","'params","'",":","kwargs",",","'previous","'",":","None","}"]
docstr: De-dummy code a dummy-coded dataframe obtained with pd.get_dummies().
  
  After reversing dummy coding the corresponding fields will be converted
  to categorical.
  
  Args:
      df (pandas.DataFrame): Input dummy coded dataframe
      sep (char): Separator between base name and dummy code
      set_category (bool): Set the de-dummy coded features
              to categorical type
  
  Examples:
      >>> columns = ["Age", "Gender=Male", "Gender=Female"]
      >>> df = pd.DataFrame([[10, 1, 0], [20, 0, 1]], columns=columns)
      >>> _de_dummy_code_df(df, sep="=")
         Age  Gender
      0   10    Male
      1   20  Female
docstr_tok: ["De-dummy","code","a","dummy-coded","dataframe","obtained","with","pd.get_dummies","(",")",".","After","reversing","dummy","coding","the","corresponding","fields","will","be","converted","to","categorical",".","Args",":","df","(","pandas.DataFrame",")",":","Input","dummy","coded","dataframe","sep","(","char",")",":","Separator","between","base","name","and","dummy","code","set_category","(","bool",")",":","Set","the","de-dummy","coded","features","to","categorical","type","Examples",":",">",">",">","columns","=","[","``","Age","''",",","``","Gender=Male","''",",","``","Gender=Female","''","]",">",">",">","df","=","pd.DataFrame","(","[","[","10",",","1",",","0","]",",","[","20",",","0",",","1","]","]",",","columns=columns",")",">",">",">","_de_dummy_code_df","(","df",",","sep=","''","=","''",")","Age","Gender","0","10","Male","1","20","Female"]
code: def _de_dummy_code_df(df, sep="=", set_category=False):
      """De-dummy code a dummy-coded dataframe obtained with pd.get_dummies().
  
      After reversing dummy coding the corresponding fields will be converted
      to categorical.
  
      Args:
          df (pandas.DataFrame): Input dummy coded dataframe
          sep (char): Separator between base name and dummy code
          set_category (bool): Set the de-dummy coded features
                  to categorical type
  
      Examples:
          >>> columns = ["Age", "Gender=Male", "Gender=Female"]
          >>> df = pd.DataFrame([[10, 1, 0], [20, 0, 1]], columns=columns)
          >>> _de_dummy_code_df(df, sep="=")
             Age  Gender
          0   10    Male
          1   20  Female
      """
  
      (
          feature_names_dum_d,
          feature_names_nodum,
      ) = StructuredDataset._parse_feature_names(df.columns)
      df_new = pd.DataFrame(
          index=df.index,
          columns=feature_names_nodum
          + list(feature_names_dum_d.keys()),
      )
  
      for fname in feature_names_nodum:
          df_new[fname] = df[fname].values.copy()
  
      for fname, vl in feature_names_dum_d.items():
          for v in vl:
              df_new.loc[df[fname + sep + str(v)] == 1, fname] = str(v)
  
      if set_category:
          for fname in feature_names_dum_d.keys():
              df_new[fname] = df_new[fname].astype("category")
  
      return df_new
  
imports: from collections import defaultdict
  from contextlib import contextmanager
  from copy import deepcopy
  from logging import warning
  import numpy
  import pandas
  from aif360.datasets import Dataset
label_desc: Use image node_id 14 for calling the StructuredDataset obj's underlying member method code with example usage: obj._de_dummy_code_df(df, sep, set_category) and returns: df_new