Registry / data / collections-extended

collections-extended

JSON →
library2.0.2pypypi✓ verified 24d ago

collections_extended is a pure Python module with no dependencies providing various extended collection types. It includes a bag (multiset) class, a setlist (ordered set / unique list) class, a bijection, a RangeMap, and an IndexedDict. It also offers frozen (hashable) variants of bags and setlists. The current version, 2.0.2, maintains an active development status with regular updates and is compatible with Python 3.7+.

pip install collections-extended
INSTALL
IMPORT
SIG · COLLECTIONS-EXTEND
C
collections-extended
datapythonv2.0.2
Install
1.5s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bag
from collections_extended import bag
setlist
from collections_extended import setlist
IndexedDict
from collections_extended import IndexedDict
RangeMap
from collections_extended import RangeMap
bijection
from collections_extended import bijection
frozenbag
from collections_extended import frozenbag
frozensetlist
from collections_extended import frozensetlist

Demonstrates basic usage of `bag`, `setlist`, `IndexedDict`, and `RangeMap` from `collections-extended`.

from collections_extended import bag, setlist, IndexedDict, RangeMap from datetime import date # Example with bag (multiset) b = bag('abracadabra') print(f"Bag: {b}, Count of 'a': {b.count('a')}") b.remove('a') print(f"Bag after removing 'a': {b}, Count of 'a': {b.count('a')}") # Example with setlist (ordered set) sl = setlist('abracadabra') print(f"Setlist: {sl}, element at index 3: {sl[3]}") try: sl.insert(1, 'd') except ValueError as e: print(f"Attempted to insert duplicate into setlist: {e}") # Example with IndexedDict idict = IndexedDict({'a': 1, 'b': 2, 'c': 3}) print(f"IndexedDict: {idict}, value at index 1: {idict.iloc[1]}") # Example with RangeMap version_map = RangeMap() version_map[date(2017, 10, 20): date(2017, 10, 27)] = '0.10.1' version_map[date(2017, 10, 27):] = '1.0.0' print(f"Version for 2017-10-24: {version_map[date(2017, 10, 24)]}")
Debug
Known issues
breakingVersion 2.0.0 dropped support for Python 2.7, 3.4, and 3.5. Ensure your environment is Python 3.6 or later for v2.x.
fix
Upgrade Python to 3.7+ or pin collections-extended to a 1.x version if Python 2.7/3.4/3.5 support is required.
affects: >=2.0.0
breakingWhen multiplying `bag` objects, the behavior changed in v2.0.0. It now produces a cartesian product as a tuple, rather than adding elements.
fix
Review code that uses `bag` multiplication (`*`) and adjust logic if the previous 'addition' behavior was expected. The new behavior is a cartesian product, yielding tuples.
affects: >=2.0.0
breakingAs of v2.0.0, `bags` no longer inherit from `Set`, meaning they cannot be compared for equality directly with `Set` objects.
fix
If comparing `bag` instances with `set` instances, explicit conversion (e.g., `set(my_bag) == my_set`) or a different comparison logic may be necessary.
affects: >=2.0.0
breakingInternal base classes `_basebag` and `_basesetlist` were renamed to `Bag` and `SetList` respectively and are now exposed in v2.0.0.
fix
Update any direct imports or references to `_basebag` or `_basesetlist` to use `Bag` or `SetList`.
affects: >=2.0.0
gotchaCalling `setlist.insert(index, element)` will raise a `ValueError` if the `element` is already present in the `setlist`.
fix
Check for element existence (e.g., `if element not in my_setlist: my_setlist.insert(...)`) or handle the `ValueError` if duplicate insertion is attempted.
affects: All versions
gotcha`setlist` objects are not comparable using ordering operators (`<`, `>`, `<=`, `>=`) due to the ambiguity between set comparison and order-based comparison. Equality (`==`, `!=`) still works.
fix
If order-sensitive comparison is needed, convert `setlist` to a `list`. For set-based comparison, convert to a `set`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'collections_extended'
The collections-extended package is not installed in the Python environment, or there's a typo in the import statement.
fix
Ensure the package is installed using pip: `pip install collections-extended` and that the import statement is `from collections_extended import ...`.
TypeError: unhashable type: 'list'
This error typically occurs when attempting to add unhashable objects (like lists or dictionaries) to a `bag` or `frozenbag` instance, which, similar to `collections.Counter`, requires its elements to be hashable to count them.
fix
Ensure that elements added to `bag` or `frozenbag` are hashable. Use tuples instead of lists if the order matters, or convert mutable objects to their hashable equivalents before adding them.
AttributeError: 'frozenbag' object has no attribute 'add'
You are attempting to modify an immutable collection (like `frozenbag` or `frozensetlist`) after it has been created. Frozen collections are designed to be hashable and their contents cannot be changed once initialized.
fix
Use the mutable versions (`bag` or `setlist`) if you need to add, remove, or modify elements after creation. If you need a modified version of a frozen collection, create a new one from the old one, e.g., `new_frozenbag = frozenbag(old_frozenbag | {'new_item'})`.
from collections_extended import Bag
The imported class name 'Bag' (with a capital 'B') does not exist or is not exposed directly for import in the `collections_extended` module. The module typically exposes its collection types with lowercase names.
fix
Use the correct lowercase class name for import: `from collections_extended import bag`.
Upgrade
Version history
2.0.2latest on PyPI · released Jan 23, 2022
Audit
Dependencies
pythonrequiredRequired Python version compatibility.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
collections-extended — pip install collections-extended · libregistry