Skip to main content

Memory-efficient container for list-like objects

Project description

PyPI-Server Unit tests

CompressedList Implementation in Python

A Python implementation of the CompressedList class from R/Bioconductor for memory-efficient list-like objects.

CompressedList is a memory-efficient container for list-like objects. Instead of storing each list element separately, it concatenates all elements into a single vector-like object and maintains information about where each original element begins and ends. This approach is significantly more memory-efficient than standard lists, especially when dealing with many list elements.

Install

To get started, install the package from PyPI

pip install compressed-lists

Usage

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

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

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

# 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

The Partitioning class handles the information about where each element begins and ends in the concatenated data. It allows for efficient extraction of elements without storing each element separately.

from compressed_lists import Partitioning

# Create partitioning from end positions
ends = [3, 5, 10]
names = ["A", "B", "C"]
part = Partitioning(ends, names)

# Get partition range for an element
start, end = part[1]  # Returns (3, 5)

[!NOTE]

Check out the documentation for available compressed list implementations and extending CompressedLists to custom data types.

Note

This project has been set up using BiocSetup and PyScaffold.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compressed_lists-0.4.4.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compressed_lists-0.4.4-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file compressed_lists-0.4.4.tar.gz.

File metadata

  • Download URL: compressed_lists-0.4.4.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for compressed_lists-0.4.4.tar.gz
Algorithm Hash digest
SHA256 f4e55978d9b7247ccfc6c98ef37cee757083325a9a6cdc5c8e98e0e23481fe06
MD5 d660d09718a1722b7b8229b2558d73fd
BLAKE2b-256 86fd67563cf7bd8b2e9a432d57029081f6ad96a6b73ca61aa2b50c9553d7abdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for compressed_lists-0.4.4.tar.gz:

Publisher: publish-pypi.yml on BiocPy/compressed-lists

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file compressed_lists-0.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for compressed_lists-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 91f63a19ced64b954c7023b28e29f1c7577e04d3b71247af2ae2e7b578ca043e
MD5 e85e66db8334ddf6fc0734fa52bf0414
BLAKE2b-256 f3ca69ba3f7d44498ed702c65fcebf246d91dfcc89990dd894f054be2261ac40

See more details on using hashes here.

Provenance

The following attestation bundles were made for compressed_lists-0.4.4-py3-none-any.whl:

Publisher: publish-pypi.yml on BiocPy/compressed-lists

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page