Help with concat

I was looking for a solution to the same issue and while your solution partially works, I don’t think it ensures the order of the genes is correct.

In case others find this thread, my modified suggestion is:

# merge obs & X
adatac = ad.concat([adata1, adata2], axis=0, join="outer", merge="first")
# merge var
merged_var = pd.concat([adata1.var, adata2.var], join="outer")
merged_var = merged_var[~merged_var.index.duplicated()]
adatac.var = merged_var.loc[adatac.var_names]

The last line of code ensures that the gene order of the merged_var DataFrame is the same as the gene names in the original AnnData object.