docs: def dump_tables_to_tskit(pop):
      """
      Converts fwdpy11.TableCollection to an
      tskit.TreeSequence
      """
      node_view = np.array(pop.tables.nodes, copy=True)
      node_view['time'] -= node_view['time'].max()
      node_view['time'][np.where(node_view['time'] != 0.0)[0]] *= -1.0
      edge_view = np.array(pop.tables.edges, copy=False)
      mut_view = np.array(pop.tables.mutations, copy=False)
  
      tc = tskit.TableCollection(pop.tables.genome_length)
  
      # We must initialize population and individual
      # tables before we can do anything else.
      # Attempting to set population to anything
      # other than -1 in an tskit.NodeTable will
      # raise an exception if the PopulationTable
      # isn't set up.
      _initializePopulationTable(node_view, tc)
      node_to_individual = _initializeIndividualTable(pop, tc)
  
      individual = [-1 for i in range(len(node_view))]
      for k, v in node_to_individual.items():
          individual[k] = v
      flags = [1]*2*pop.N + [0]*(len(node_view) - 2*pop.N)
      # Bug fixed in 0.3.1: add preserved nodes to samples list
      for i in pop.tables.preserved_nodes:
          flags[i] = 1
      tc.nodes.set_columns(flags=flags, time=node_view['time'],
                           population=node_view['population'],
                           individual=individual)
      tc.edges.set_columns(left=edge_view['left'],
                           right=edge_view['right'],
                           parent=edge_view['parent'],
                           child=edge_view['child'])
  
      mpos = np.array([pop.mutations[i].pos for i in mut_view['key']])
      ancestral_state = np.zeros(len(mut_view), dtype=np.int8)+ord('0')
      ancestral_state_offset = np.arange(len(mut_view)+1, dtype=np.uint32)
      tc.sites.set_columns(position=mpos,
                           ancestral_state=ancestral_state,
                           ancestral_state_offset=ancestral_state_offset)
  
      derived_state = np.zeros(len(mut_view), dtype=np.int8)+ord('1')
      md, mdo = _generate_mutation_metadata(pop)
      tc.mutations.set_columns(site=np.arange(len(mpos), dtype=np.int32),
                               node=mut_view['node'],
                               derived_state=derived_state,
                               derived_state_offset=ancestral_state_offset,
                               metadata=md,
                               metadata_offset=mdo)
      return tc.tree_sequence()