class_docstr: Non permanent document
  
  This document is meant for debugging purposes within the EphemeralDB.
  
  .. seealso:: :class:`orion.core.io.database.ephemeraldb.EphemeralDB` for database object.
class_docstr_tok: ["Non","permanent","document","This","document","is","meant","for","debugging","purposes","within","the","EphemeralDB",".","..","seealso",":",":",":","class",":","`","orion.core.io.database.ephemeraldb.EphemeralDB","`","for","database","object","."]
docstr: Verify that all keys are 0 or 1 (with exception of _id) and convert them.
  
  For simplicity, when keys are 0, the inverse set of keys for 1s is computed.
  
  .. note ::
  
      _id is set to 1 if not specified. Only _id may be set to 0 if other keys are set to 1.
docstr_tok: ["Verify","that","all","keys","are","0","or","1","(","with","exception","of","_id",")","and","convert","them",".","For","simplicity",",","when","keys","are","0",",","the","inverse","set","of","keys","for","1s","is","computed",".","..","note",":",":","_id","is","set","to","1","if","not","specified",".","Only","_id","may","be","set","to","0","if","other","keys","are","set","to","1","."]
code: def _validate_keys(self, keys):
      """Verify that all keys are 0 or 1 (with exception of _id) and convert them.
  
      For simplicity, when keys are 0, the inverse set of keys for 1s is computed.
  
      .. note ::
  
          _id is set to 1 if not specified. Only _id may be set to 0 if other keys are set to 1.
      """
      if len(keys) == 1 and keys.get("_id", 0) == 1:
          return keys
  
      keys_without_id = [key for key in keys if key != "_id"]
      n_keys = sum(keys[key] for key in keys_without_id)
      if n_keys != 0 and n_keys != len(keys_without_id):
          raise ValueError(
              f"Cannot mix selection with 1 and 0s except for _id: {keys}"
          )
  
      # All given keys are 0 (with possible exception of _id)
      if n_keys == 0:
          new_keys = {
              key: 1 for key in self._data.keys() if key not in keys
          }
          new_keys["_id"] = keys.get("_id", 1)
          keys = new_keys
  
      keys.setdefault("_id", 1)
  
      return keys
  
imports: import copy
  from collections import defaultdict
  from orion.core.io.database import Database, DatabaseError, DuplicateKeyError
  from orion.core.utils.flatten import flatten, unflatten
label_desc: Use image node_id 6 for calling the EphemeralDocument obj's underlying member method code with example usage: obj._validate_keys(keys) and returns: keys, keys