@@ -378,7 +378,10 @@ def __getitem__(self, key: Union[int, str, slice]) -> Any:
378378 return self .extract_range (start , end )
379379
380380 # slices
381- elif isinstance (key , slice ):
381+ elif isinstance (key , (range , slice )):
382+ if isinstance (key , range ):
383+ key = slice (key .start , key .stop , key .step )
384+
382385 indices = range (* key .indices (len (self )))
383386 result = []
384387 for i in indices :
@@ -531,6 +534,10 @@ def extract_subset(self, indices: Sequence[int]) -> CompressedList:
531534 Returns:
532535 A new CompressedList with only the selected elements.
533536 """
537+ print ("here" , indices , type (indices ))
538+ if isinstance (indices , np .ndarray ):
539+ indices = indices .tolist ()
540+
534541 # Validate indices
535542 for i in indices :
536543 if i < 0 or i >= len (self ):
@@ -544,16 +551,25 @@ def extract_subset(self, indices: Sequence[int]) -> CompressedList:
544551 new_partitioning = Partitioning .from_lengths (new_lengths , new_names )
545552
546553 # Extract data
547- new_data = []
554+ _new_data = []
548555 for i in indices :
549556 start , end = self ._partitioning .get_partition_range (i )
550- if isinstance (self ._unlist_data , np .ndarray ):
551- new_data .append (self ._unlist_data [start :end ])
552- else :
553- new_data .extend (self ._unlist_data [start :end ])
554-
555- if isinstance (self ._unlist_data , np .ndarray ):
556- new_data = np .concatenate (new_data )
557+ _subset = ut .subset_sequence (self ._unlist_data , [j for j in range (start , end )])
558+ _new_data .append (_subset )
559+ # if isinstance(self._unlist_data, np.ndarray):
560+ # new_data.append(self._unlist_data[start:end])
561+ # else:
562+ # new_data.extend(self._unlist_data[start:end])
563+
564+ # if isinstance(self._unlist_data, np.ndarray):
565+ # new_data = np.concatenate(new_data)
566+
567+ if len (_new_data ) == 1 :
568+ new_data = _new_data [0 ]
569+ elif len (_new_data ) > 0 :
570+ new_data = ut .combine_sequences (* _new_data )
571+ else :
572+ new_data = []
557573
558574 current_class_const = type (self )
559575 return current_class_const (
0 commit comments