Skip to content

Commit 2a63f11

Browse files
committed
added test for concatenation checking order
1 parent 7f5ffa5 commit 2a63f11

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

anndata/base.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1097,11 +1097,14 @@ def _set_backed(self, attr, value):
10971097
self.file._file.create_dataset(attr, data=value)
10981098

10991099
def _normalize_indices(self, index):
1100+
# deal with tuples of length 1
1101+
if isinstance(index, tuple) and len(index) == 1:
1102+
index = index[0]
11001103
# deal with pd.Series
11011104
if isinstance(index, pd.Series):
11021105
index = index.values
11031106
if isinstance(index, tuple):
1104-
if len(index) != 2:
1107+
if len(index) > 2:
11051108
raise ValueError(
11061109
'AnnData can only be sliced in rows and columns.')
11071110
# deal with pd.Series
@@ -1111,9 +1114,12 @@ def _normalize_indices(self, index):
11111114
index = index[0].values, index[1]
11121115
# one of the two has to be a slice
11131116
if not (isinstance(index[0], slice) or isinstance(index[1], slice)):
1114-
raise ValueError(
1115-
'Slicing with two indices at the same time is not yet implemented. '
1116-
'As a workaround, do row and column slicing succesively.')
1117+
if (isinstance(index[0], (int, str, None)) and isinstance(index[1], (int, str, None))):
1118+
pass # two scalars are fine
1119+
else:
1120+
raise ValueError(
1121+
'Slicing with two indices at the same time is not yet implemented. '
1122+
'As a workaround, do row and column slicing succesively.')
11171123
obs, var = super(AnnData, self)._unpack_index(index)
11181124
obs = _normalize_index(obs, self.obs_names)
11191125
var = _normalize_index(var, self.var_names)

anndata/tests/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def test_concatenate():
195195
'anno2': ['d3', 'd4']},
196196
{'var_names': ['d', 'c', 'b']})
197197
adata = adata1.concatenate(adata2, adata3)
198+
assert adata.X.astype(int).tolist() == [[2, 3], [5, 6], [3, 2], [6, 5], [3, 2], [6, 5]]
198199
assert adata.n_vars == 2
199200
assert adata.obs_keys() == ['anno1', 'anno2', 'batch']
200201
adata = adata1.concatenate(adata2, adata3, batch_key='batch1')

0 commit comments

Comments
 (0)