code: def write_metadata(hdf5_out, dim, metadata_df, convert_back_to_neg_666, gzip_compression):
      
      if dim == "col":
          hdf5_out.create_group(col_meta_group_node)
          metadata_node_name = col_meta_group_node
      elif dim == "row":
          hdf5_out.create_group(row_meta_group_node)
          metadata_node_name = row_meta_group_node
      else:
          logger.error("'dim' argument must be either 'row' or 'col'!")
  
      # write id field to expected node
      hdf5_out.create_dataset(metadata_node_name + "/id", data=[numpy.string_(x) for x in metadata_df.index],
          compression=gzip_compression)
  
      metadata_fields = list(metadata_df.columns.copy())
  
      # if specified, convert numpy.nans in metadata back to -666
      if convert_back_to_neg_666:
          for c in metadata_fields:
              metadata_df[[c]] = metadata_df[[c]].replace([numpy.nan], ["-666"])
  
      # write metadata columns to their own arrays
      for field in [entry for entry in metadata_fields if entry != "ind"]:
          if numpy.array(metadata_df.loc[:, field]).dtype.type in (numpy.str_, numpy.object_):
              array_write = numpy.array(metadata_df.loc[:, field]).astype('S')
          else:
              array_write = numpy.array(metadata_df.loc[:, field])
          hdf5_out.create_dataset(metadata_node_name + "/" + field,
                                  data=array_write,
                                  compression=gzip_compression)
docs: Writes either column or row metadata to proper node of gctx out (hdf5) file.
  
  	Input:
  		- hdf5_out (h5py): open hdf5 file to write to
  		- dim (str; must be "row" or "col"): dimension of metadata to write to 
  		- metadata_df (pandas DataFrame): metadata DataFrame to write to file 
  		- convert_back_to_neg_666 (bool): Whether to convert numpy.nans back to "-666",
  				as per CMap metadata null convention