docs: def _encode_dict_as_row(record, column_name_map):
      """ Encode a dictionary representing a table row in a form suitable for streaming to BQ.
  
        This includes encoding timestamps as ISO-compatible strings and removing invalid
        characters from column names.
  
      Args:
        record: a Python dictionary representing the table row.
        column_name_map: a dictionary mapping dictionary keys to column names. This is initially
          empty and built up by this method when it first encounters each column, then used as a
          cache subsequently.
      Returns:
        The sanitized dictionary.
      """
      for k in list(record.keys()):
        v = record[k]
        # If the column is a date, convert to ISO string.
        if isinstance(v, pandas.Timestamp) or isinstance(v, datetime.datetime):
          v = record[k] = record[k].isoformat()
  
        # If k has invalid characters clean it up
        if k not in column_name_map:
          column_name_map[k] = ''.join(c for c in k if c in Table._VALID_COLUMN_NAME_CHARACTERS)
        new_k = column_name_map[k]
        if k != new_k:
          record[new_k] = v
          del record[k]
      return record