code: def write(filename, adata, ext=None, compression='gzip', compression_opts=None):
      
      filename = str(filename)  # allow passing pathlib.Path objects
      if is_valid_filename(filename):
          filename = filename
          ext_ = is_valid_filename(filename, return_ext=True)
          if ext is None:
              ext = ext_
          elif ext != ext_:
              raise ValueError('It suffices to provide the file type by '
                               'providing a proper extension to the filename.'
                               'One of "txt", "csv", "h5" or "npz".')
      else:
          key = filename
          ext = settings.file_format_data if ext is None else ext
          filename = get_filename_from_key(key, ext)
      if ext == 'csv':
          adata.write_csvs(filename)
      else:
          adata.write(filename, compression=compression,
                      compression_opts=compression_opts)
docs: Write :class:`~anndata.AnnData` objects to file.
  
      Parameters
      ----------
      filename : `str`
          If the filename has no file extension, it is interpreted as a key for
          generating a filename via `sc.settings.writedir + filename +
          sc.settings.file_format_data`.  This is the same behavior as in
          :func:`~scanpy.api.read`.
      adata : :class:`~anndata.AnnData`
          Annotated data matrix.
      ext : {`None`, `'h5'`, `'csv'`, `'txt'`, `'npz'`} (default: `None`)
          File extension from wich to infer file format. If `None`, defaults to
          `sc.settings.file_format_data`.
      compression : {`None`, 'gzip', 'lzf'}, optional (default: `'gzip'`)
          See http://docs.h5py.org/en/latest/high/dataset.html.
      compression_opts : `int`, optional (default: `None`)
          See http://docs.h5py.org/en/latest/high/dataset.html.