Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Version 0.4.0 - 0.4.2
## Version 0.4.0 - 0.4.3

- Classes extend `BiocObject` from biocutils. `metadata` is a named list.
- Update actions to run from 3.10-3.14
Expand Down
34 changes: 25 additions & 9 deletions src/compressed_lists/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ def __getitem__(self, key: Union[int, str, slice]) -> Any:
return self.extract_range(start, end)

# slices
elif isinstance(key, slice):
elif isinstance(key, (range, slice)):
if isinstance(key, range):
key = slice(key.start, key.stop, key.step)

indices = range(*key.indices(len(self)))
result = []
for i in indices:
Expand Down Expand Up @@ -531,6 +534,10 @@ def extract_subset(self, indices: Sequence[int]) -> CompressedList:
Returns:
A new CompressedList with only the selected elements.
"""
print("here", indices, type(indices))
if isinstance(indices, np.ndarray):
indices = indices.tolist()

# Validate indices
for i in indices:
if i < 0 or i >= len(self):
Expand All @@ -544,16 +551,25 @@ def extract_subset(self, indices: Sequence[int]) -> CompressedList:
new_partitioning = Partitioning.from_lengths(new_lengths, new_names)

# Extract data
new_data = []
_new_data = []
for i in indices:
start, end = self._partitioning.get_partition_range(i)
if isinstance(self._unlist_data, np.ndarray):
new_data.append(self._unlist_data[start:end])
else:
new_data.extend(self._unlist_data[start:end])

if isinstance(self._unlist_data, np.ndarray):
new_data = np.concatenate(new_data)
_subset = ut.subset_sequence(self._unlist_data, [j for j in range(start, end)])
_new_data.append(_subset)
# if isinstance(self._unlist_data, np.ndarray):
# new_data.append(self._unlist_data[start:end])
# else:
# new_data.extend(self._unlist_data[start:end])

# if isinstance(self._unlist_data, np.ndarray):
# new_data = np.concatenate(new_data)

if len(_new_data) == 1:
new_data = _new_data[0]
elif len(_new_data) > 0:
new_data = ut.combine_sequences(*_new_data)
else:
new_data = []

current_class_const = type(self)
return current_class_const(
Expand Down