Skip to content

Commit 19b2e6a

Browse files
committed
proper warning for non-unique observation names after concatenation
1 parent 2a8c499 commit 19b2e6a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

anndata/base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ def concatenate(self, *adatas, join='inner', batch_key='batch', batch_categories
13711371
logg.info(
13721372
'Making variable names unique for controlled concatenation.')
13731373
printed_info = True
1374-
1374+
13751375
mergers = dict(inner=set.intersection, outer=set.union)
13761376
var_names = pd.Index(reduce(mergers[join], (set(ad.var_names) for ad in all_adatas)))
13771377

@@ -1402,6 +1402,9 @@ def concatenate(self, *adatas, join='inner', batch_key='batch', batch_categories
14021402
# obs
14031403
obs = ad.obs.copy()
14041404
obs[batch_key] = pd.Categorical(ad.n_obs * [categories[i]], categories)
1405+
if (is_string_dtype(all_adatas[0].obs.index) and not
1406+
is_string_dtype(ad.obs.index)):
1407+
obs.index = obs.index.astype(str)
14051408
if index_unique is not None:
14061409
if not is_string_dtype(ad.obs.index):
14071410
obs.index = obs.index.astype(str)
@@ -1415,7 +1418,12 @@ def concatenate(self, *adatas, join='inner', batch_key='batch', batch_categories
14151418
uns = all_adatas[0].uns
14161419
obsm = np.concatenate([ad.obsm for ad in all_adatas])
14171420
varm = self.varm # TODO
1418-
return AnnData(X, obs, var, uns, obsm, None, filename=self.filename)
1421+
1422+
new_adata = AnnData(X, obs, var, uns, obsm, None, filename=self.filename)
1423+
if not obs.index.is_unique:
1424+
logg.info(
1425+
'Or pass `index_unique!=None` to `.concatenate`.')
1426+
return new_adata
14191427

14201428
def var_names_make_unique(self, join='-'):
14211429
self.var.index = utils.make_index_unique(self.var.index, join)

0 commit comments

Comments
 (0)