title: DatasetDict containing Datasets with different features when pushed to hub gets remapped features
comments: Hi @pietrolesci, thanks for reporting.
  
  Please note that this is a design purpose: a `DatasetDict` has the same features for all its datasets. Normally, a `DatasetDict` is composed of several sub-datasets each corresponding to a different **split**.
  
  To handle sub-datasets with different features, we use another approach: use different **configurations** instead of **splits**.
  
  However, for the moment `push_to_hub` does not support specifying different configurations. IMHO, we should implement this. Hi @albertvillanova,
  
  Thanks a lot for your reply! I got it now. The strange thing for me was to have it correctly working (i.e., DatasetDict with different features in some datasets) locally and not on the Hub. It would be great to have configuration supported by `push_to_hub`. Personally, this latter functionality allowed me to iterate rather quickly on dataset curation.
  
  Again, thanks for your time @albertvillanova!
  
  Best,
  Pietro Hi! Yes, we should override `DatasetDict.__setitem__` and throw an error if features dictionaries are different. `DatasetDict` is a subclass of `dict`, so `DatasetDict.{update/setdefault}` need to be overridden as well. We could avoid this by subclassing `UserDict`, but then we would get the name collision - `DatasetDict.data` vs. `UserDict.data`. This makes me think we should rename the `data` attribute of `DatasetDict`/`Dataset` for easier dict subclassing (would also simplify https://github.com/huggingface/datasets/pull/3997) and to follow good Python practices. Another option is to have a custom `UserDict` class in `py_utils`, but it can be hard to keep this class consistent with the built-in `UserDict`. 
  
  @albertvillanova @lhoestq wdyt? I would keep things simple and keep subclassing dict. Regarding the features check, I guess this can be done only for `push_to_hub` right ? It is the only function right now that requires the underlying datasets to be splits (e.g. train/test) and have the same features.
  
  Note that later you will be able to push datasets with different features as different dataset **configurations** (similarly to the [GLUE subsets](https://huggingface.co/datasets/glue) for example). We will work on this soon
body: Hi there,
  
  I am trying to load a dataset to the Hub. This dataset is a `DatasetDict` composed of various splits. Some splits have a different `Feature` mapping. Locally, the DatasetDict preserves the individual features but if I `push_to_hub` and then `load_dataset`, the features are all the same.
  
  Dataset and code to reproduce available [here](https://huggingface.co/datasets/pietrolesci/robust_nli).
  
  In short:
  
  I have 3 feature mapping
  ```python
  Tri_features = Features(
      {
          "idx": Value(dtype="int64"),
          "premise": Value(dtype="string"),
          "hypothesis": Value(dtype="string"),
          "label": ClassLabel(num_classes=3, names=["entailment", "neutral", "contradiction"]),
      }
  )
  
  Ent_features = Features(
      {
          "idx": Value(dtype="int64"),
          "premise": Value(dtype="string"),
          "hypothesis": Value(dtype="string"),
          "label": ClassLabel(num_classes=2, names=["non-entailment", "entailment"]),
      }
  )
  
  Con_features = Features(
      {
          "idx": Value(dtype="int64"),
          "premise": Value(dtype="string"),
          "hypothesis": Value(dtype="string"),
          "label": ClassLabel(num_classes=2, names=["non-contradiction", "contradiction"]),
      }
  )
  ```
  
  Then I create different datasets
  
  ```python
  dataset_splits = {}
  
  for split in df["split"].unique():
      print(split)
      df_split = df.loc[df["split"] == split].copy()
      
      if split in Tri_dataset:
          df_split["label"] = df_split["label"].map({"entailment": 0, "neutral": 1, "contradiction": 2})
          ds = Dataset.from_pandas(df_split, features=Tri_features)
      
      elif split in Ent_bin_dataset:
          df_split["label"] = df_split["label"].map({"non-entailment": 0, "entailment": 1})
          ds = Dataset.from_pandas(df_split, features=Ent_features)
      
      elif split in Con_bin_dataset:
          df_split["label"] = df_split["label"].map({"non-contradiction": 0, "contradiction": 1})
          ds = Dataset.from_pandas(df_split, features=Con_features)
  
      else:
          print("ERROR:", split)
      dataset_splits[split] = ds
  datasets = DatasetDict(dataset_splits)
  ```
  
  I then push to hub
  
  ```python
  datasets.push_to_hub("pietrolesci/robust_nli", token="<token>")
  ```
  
  Finally, I load it from the hub
  
  ```python
  datasets_loaded_from_hub = load_dataset("pietrolesci/robust_nli")
  ```
  
  And I get that
  
  ```python
  datasets["LI_TS"].features != datasets_loaded_from_hub["LI_TS"].features
  ```
  
  since 
  
  ```python
  "label": ClassLabel(num_classes=2, names=["non-contradiction", "contradiction"])
  ```
  
  gets remapped to 
  
  ```python
   "label": ClassLabel(num_classes=3, names=["entailment", "neutral", "contradiction"])
  ```