@@ -1097,11 +1097,14 @@ def _set_backed(self, attr, value):
1097
1097
self .file ._file .create_dataset (attr , data = value )
1098
1098
1099
1099
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 ]
1100
1103
# deal with pd.Series
1101
1104
if isinstance (index , pd .Series ):
1102
1105
index = index .values
1103
1106
if isinstance (index , tuple ):
1104
- if len (index ) != 2 :
1107
+ if len (index ) > 2 :
1105
1108
raise ValueError (
1106
1109
'AnnData can only be sliced in rows and columns.' )
1107
1110
# deal with pd.Series
@@ -1111,9 +1114,12 @@ def _normalize_indices(self, index):
1111
1114
index = index [0 ].values , index [1 ]
1112
1115
# one of the two has to be a slice
1113
1116
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.' )
1117
1123
obs , var = super (AnnData , self )._unpack_index (index )
1118
1124
obs = _normalize_index (obs , self .obs_names )
1119
1125
var = _normalize_index (var , self .var_names )
0 commit comments