File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -118,14 +118,22 @@ def unpack_index(index: Index) -> Tuple[Index1D, Index1D]:
118118
119119
120120@singledispatch
121- def _subset (a : Union [np .ndarray , spmatrix , pd .DataFrame ], subset_idx : Index ):
121+ def _subset (a : Union [np .ndarray , pd .DataFrame ], subset_idx : Index ):
122122 # Select as combination of indexes, not coordinates
123123 # Correcting for indexing behaviour of np.ndarray
124124 if all (isinstance (x , cabc .Iterable ) for x in subset_idx ):
125125 subset_idx = np .ix_ (* subset_idx )
126126 return a [subset_idx ]
127127
128128
129+ @_subset .register (spmatrix )
130+ def _subset_spmatrix (a : spmatrix , subset_idx : Index ):
131+ # Correcting for indexing behaviour of sparse.spmatrix
132+ if len (subset_idx ) > 1 and all (isinstance (x , cabc .Iterable ) for x in subset_idx ):
133+ subset_idx = (subset_idx [0 ].reshape (- 1 , 1 ), * subset_idx [1 :])
134+ return a [subset_idx ]
135+
136+
129137@_subset .register (pd .DataFrame )
130138def _subset_df (df : pd .DataFrame , subset_idx : Index ):
131139 return df .iloc [subset_idx ]
You can’t perform that action at this time.
0 commit comments