Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c131bf0
Use typed lists from biocutils for compressed lists
jkanche Aug 27, 2025
1d01f85
Update changelog
jkanche Aug 27, 2025
c475591
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2025
4b9ca3d
fix element type
jkanche Aug 27, 2025
3d044d1
Merge branch 'use-biocutils' of https://github.com/BiocPy/compressed-…
jkanche Aug 27, 2025
220aad0
Compressed NumPy lis
jkanche Aug 27, 2025
e9f5fc4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2025
16d899d
Base is not an abstract class anymore
jkanche Aug 28, 2025
fc0088b
Merge branch 'use-biocutils' of https://github.com/BiocPy/compressed-…
jkanche Aug 28, 2025
be24a2f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2025
b0c56ac
update test
jkanche Sep 17, 2025
4c496b9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2025
7c7f2be
thinking of split generic
jkanche Sep 17, 2025
af5fef2
Merge branch 'use-biocutils' of https://github.com/BiocPy/compressed-…
jkanche Sep 17, 2025
8d32fee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2025
b5424d4
implement generic
jkanche Sep 18, 2025
4e6f146
Merge branch 'use-biocutils' of https://github.com/BiocPy/compressed-…
jkanche Sep 18, 2025
f59bdfe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2025
1265d6c
fix import
jkanche Sep 18, 2025
7cb7971
adding the generic and other changes to support initialization
jkanche Oct 7, 2025
e58ff7b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2025
056f32a
cleaning up numpylists
jkanche Oct 8, 2025
9e0fda4
Merge branch 'use-biocutils' of https://github.com/BiocPy/compressed-…
jkanche Oct 8, 2025
00e6c89
more tests for the generic
jkanche Oct 8, 2025
155e8aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2025
7c7ecba
more biocutils methods, getting rid of from_partitioned data
jkanche Oct 9, 2025
b799d71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2025
7d916a3
tests for compressed biocframe
jkanche Oct 9, 2025
06a2a2e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2025
04ac7ca
remove prints
jkanche Oct 9, 2025
fea4835
update readme and docs
jkanche Oct 9, 2025
0dd56ed
more tests and update changelog
jkanche Oct 9, 2025
423ea91
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.2.0

- Major changes to the package; Switch to typed lists from the biocutils package.

## Version 0.1.0 - 0.1.1

- Initial implementation of various classes - Partitioning and CompressedLists.
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ pip install compressed-lists

## Usage


```py
from compressed_lists import CompressedIntegerList, CompressedStringList
from compressed_lists import CompressedIntegerList, CompressedStringList, Partitioning

# Create a CompressedIntegerList
int_data = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
Expand All @@ -38,9 +37,12 @@ print(squared[0]) # [1, 4, 9]
# Convert to a regular Python list
regular_list = int_list.to_list()

# Create a CompressedStringList
char_data = [["apple", "banana"], ["cherry", "date", "elderberry"], ["fig"]]
char_list = CompressedStringList.from_list(char_data)
# Create a CompressedStringList from lengths
import biocutils as ut
char_data = ut.StringList(["apple", "banana", "cherry", "date", "elderberry", "fig"])

char_list = CompressedStringList(char_data, partitioning=Partitioning.from_lengths([2,3,1]))
print(char_list)
```

### Partitioning
Expand All @@ -61,7 +63,7 @@ start, end = part[1] # Returns (3, 5)

> [!NOTE]
>
> Check out the [documentation](https://biocpy.github.io/compressed-lists) for extending CompressedLists to custom data types.
> Check out the [documentation](https://biocpy.github.io/compressed-lists) for available compressed list implementations and extending `CompressedLists` to custom data types.

<!-- biocsetup-notes -->

Expand Down
54 changes: 30 additions & 24 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@ kernelspec:
# Basic Usage

```{code-cell}
from compressed_lists import CompressedIntegerList, CompressedStringList
from compressed_lists import CompressedIntegerList, CompressedStringList, Partitioning

# Create a CompressedIntegerList
int_data = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
names = ["A", "B", "C"]
int_list = CompressedIntegerList.from_list(int_data, names)

# Access elements
print(int_list[0]) # [1, 2, 3]
print(int_list["B"]) # [4, 5]
print(int_list[1:3]) # Slice of elements
print(int_list[0])
print(int_list["B"])
print(int_list[1:3])

# Apply a function to each element
squared = int_list.lapply(lambda x: [i**2 for i in x])
print(squared[0]) # [1, 4, 9]
print(squared[0])

# Convert to a regular Python list
regular_list = int_list.to_list()

# Create a CompressedStringList
char_data = [["apple", "banana"], ["cherry", "date", "elderberry"], ["fig"]]
char_list = CompressedStringList.from_list(char_data)
# Create a CompressedStringList from lengths
import biocutils as ut
char_data = ut.StringList(["apple", "banana", "cherry", "date", "elderberry", "fig"])

char_list = CompressedStringList(char_data, partitioning=Partitioning.from_lengths([2,3,1]))
print(char_list)
```

## Partitioning
Expand Down Expand Up @@ -57,7 +60,7 @@ print(start, end)
Create a new class that inherits from `CompressedList` with appropriate type annotations:

```python
from typing import List, TypeVar, Generic
from typing import List
from compressed_lists import CompressedList, Partitioning
import numpy as np

Expand All @@ -72,31 +75,32 @@ The constructor should initialize the superclass with the appropriate data:

```python
def __init__(self,
unlist_data: Any, # Replace with your data type
partitioning: Partitioning,
element_metadata: dict = None,
metadata: dict = None):
unlist_data: Any, # Replace with your data type
partitioning: Partitioning,
element_type: Any = None,
element_metadata: Optional[dict] = None,
metadata: Optional[dict] = None):
super().__init__(unlist_data, partitioning,
element_type="custom_type", # Set your element type
element_metadata=element_metadata,
metadata=metadata)
element_type="custom_type", # Set your element type
element_metadata=element_metadata,
metadata=metadata)
```

## 3. Implement _extract_range Method
## 3. Implement `extract_range` Method

This method defines how to extract a range of elements from your unlisted data:

```python
def _extract_range(self, start: int, end: int) -> List[T]:
def extract_range(self, start: int, end: int) -> List[T]:
"""Extract a range from unlisted data."""
# For example, with numpy arrays:
return self.unlist_data[start:end].tolist()
return self.unlist_data[start:end]

# Or for other data types:
# return self.unlist_data[start:end]
# return self.unlist_data[start:end, :]
```

## 4. Implement from_list Class Method
## 4. Implement `from_list` Class Method

This factory method creates a new instance from a list:

Expand Down Expand Up @@ -140,7 +144,7 @@ class CompressedFloatList(CompressedList):
element_metadata=element_metadata,
metadata=metadata)

def _extract_range(self, start: int, end: int) -> List[float]:
def extract_range(self, start: int, end: int) -> List[float]:
return self.unlist_data[start:end].tolist()

@classmethod
Expand Down Expand Up @@ -176,14 +180,16 @@ class MyObject:
def __init__(self, value):
self.value = value

class CompressedMyObjectList(CompressedList[List[MyObject]]):
class CompressedMyObjectList(CompressedList):
# Implementation details...

def _extract_range(self, start: int, end: int) -> List[MyObject]:
def extract_range(self, start: int, end: int) -> List[MyObject]:
return self.unlist_data[start:end]

@classmethod
def from_list(cls, lst: List[List[MyObject]], ...):
# Custom flattening and storage logic
# ...
```

Check out the `CompressedBiocFrameList` for a complete example of this usecase.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ python_requires = >=3.9
install_requires =
importlib-metadata; python_version<"3.8"
biocutils
numpy
biocframe


[options.packages.find]
Expand Down
92 changes: 0 additions & 92 deletions src/compressed_lists/CompressedIntegerList.py

This file was deleted.

86 changes: 0 additions & 86 deletions src/compressed_lists/CompressedStringList.py

This file was deleted.

11 changes: 8 additions & 3 deletions src/compressed_lists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
del version, PackageNotFoundError

from .partition import Partitioning
from .CompressedList import CompressedList
from .CompressedIntegerList import CompressedIntegerList
from .CompressedStringList import CompressedStringList
from .base import CompressedList
from .integer_list import CompressedIntegerList
from .string_list import CompressedStringList, CompressedCharacterList
from .bool_list import CompressedBooleanList
from .float_list import CompressedFloatList
from .numpy_list import CompressedNumpyList
from .biocframe_list import CompressedBiocFrameList
from .split_generic import splitAsCompressedList
Loading