compressed-lists 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.pre-commit-config.yaml +1 -1
  2. compressed_lists-0.3.0/CHANGELOG.md +17 -0
  3. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/PKG-INFO +1 -1
  4. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/tutorial.md +1 -1
  5. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/__init__.py +1 -1
  6. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/base.py +37 -12
  7. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/biocframe_list.py +64 -10
  8. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/bool_list.py +2 -2
  9. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/float_list.py +2 -2
  10. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/integer_list.py +2 -2
  11. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/numpy_list.py +14 -8
  12. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/partition.py +10 -6
  13. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/split_generic.py +40 -10
  14. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists/string_list.py +3 -3
  15. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/PKG-INFO +1 -1
  16. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/SOURCES.txt +3 -1
  17. compressed_lists-0.3.0/tests/test_base.py +132 -0
  18. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_biocframe.py +19 -5
  19. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_int.py +2 -2
  20. compressed_lists-0.3.0/tests/test_generics.py +86 -0
  21. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_partitioning.py +38 -0
  22. compressed_lists-0.3.0/tests/test_type_validations.py +32 -0
  23. compressed_lists-0.2.0/CHANGELOG.md +0 -10
  24. compressed_lists-0.2.0/tests/test_generics.py +0 -24
  25. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.coveragerc +0 -0
  26. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.github/workflows/publish-pypi.yml +0 -0
  27. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.github/workflows/run-tests.yml +0 -0
  28. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.gitignore +0 -0
  29. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/.readthedocs.yml +0 -0
  30. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/AUTHORS.md +0 -0
  31. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/CONTRIBUTING.md +0 -0
  32. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/LICENSE.txt +0 -0
  33. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/README.md +0 -0
  34. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/Makefile +0 -0
  35. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/_static/.gitignore +0 -0
  36. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/authors.md +0 -0
  37. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/changelog.md +0 -0
  38. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/conf.py +0 -0
  39. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/contributing.md +0 -0
  40. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/index.md +0 -0
  41. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/license.md +0 -0
  42. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/readme.md +0 -0
  43. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/docs/requirements.txt +0 -0
  44. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/pyproject.toml +0 -0
  45. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/setup.cfg +0 -0
  46. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/setup.py +0 -0
  47. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/dependency_links.txt +0 -0
  48. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/not-zip-safe +0 -0
  49. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/requires.txt +0 -0
  50. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/src/compressed_lists.egg-info/top_level.txt +0 -0
  51. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/conftest.py +0 -0
  52. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_bool.py +0 -0
  53. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_custom.py +0 -0
  54. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_float.py +0 -0
  55. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_numpy.py +0 -0
  56. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tests/test_comp_str.py +0 -0
  57. {compressed_lists-0.2.0 → compressed_lists-0.3.0}/tox.ini +0 -0
@@ -33,7 +33,7 @@ repos:
33
33
 
34
34
  - repo: https://github.com/astral-sh/ruff-pre-commit
35
35
  # Ruff version.
36
- rev: v0.12.9
36
+ rev: v0.13.3
37
37
  hooks:
38
38
  - id: ruff
39
39
  args: [--fix, --exit-non-zero-on-fix]
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## Version 0.3.0
4
+
5
+ - Renamed `CompressedBiocFrameList` to `CompressedSplitBiocFrameList` since the current implementation can only handle dataframes with the same number and names of columns.
6
+ - Correctly link some of the annoying typehint errors.
7
+ - `to_list` and `unlist` now perform same operation as the R implementation.
8
+ - `splitAsCompressedList` has a more abstract implementation if no generic is implemented. If it fails, returns an error.
9
+
10
+ ## Version 0.2.0
11
+
12
+ - Major changes to the package; Switch to typed lists from the biocutils package.
13
+
14
+ ## Version 0.1.0 - 0.1.1
15
+
16
+ - Initial implementation of various classes - Partitioning and CompressedLists.
17
+ - Udpate documentation, tutorial and tests.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compressed-lists
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Memory-efficient container for list-like objects
5
5
  Home-page: https://github.com/biocpy/compressed-lists
6
6
  Author: Jayaram Kancherla
@@ -192,4 +192,4 @@ class CompressedMyObjectList(CompressedList):
192
192
  # ...
193
193
  ```
194
194
 
195
- Check out the `CompressedBiocFrameList` for a complete example of this usecase.
195
+ Check out the `CompressedSplitBiocFrameList` for a complete example of this usecase.
@@ -22,5 +22,5 @@ from .string_list import CompressedStringList, CompressedCharacterList
22
22
  from .bool_list import CompressedBooleanList
23
23
  from .float_list import CompressedFloatList
24
24
  from .numpy_list import CompressedNumpyList
25
- from .biocframe_list import CompressedBiocFrameList
25
+ from .biocframe_list import CompressedSplitBiocFrameList
26
26
  from .split_generic import splitAsCompressedList
@@ -144,7 +144,13 @@ class CompressedList:
144
144
  output = f"{type(self).__name__}(number_of_elements={len(self)}"
145
145
  output += ", unlist_data=" + ut.print_truncated_list(self._unlist_data)
146
146
  output += ", partitioning=" + self._partitioning.__repr__()
147
- output += ", element_type=" + self._element_type
147
+
148
+ _etype_name = "__unknown_class__"
149
+ if isinstance(self._element_type, str):
150
+ _etype_name = self._element_type
151
+ elif hasattr(self._element_type, "__name__"):
152
+ _etype_name = self._element_type.__name__
153
+ output += ", element_type=" + _etype_name
148
154
 
149
155
  if len(self._element_metadata) > 0:
150
156
  output += ", element_metadata=" + ut.print_truncated_dict(self._element_metadata)
@@ -162,7 +168,13 @@ class CompressedList:
162
168
  """
163
169
  output = f"class: {type(self).__name__}\n"
164
170
 
165
- output += f"number of elements: ({len(self)}) of type: {self._element_type}\n"
171
+ _etype_name = "__unknown_class__"
172
+ if isinstance(self._element_type, str):
173
+ _etype_name = self._element_type
174
+ elif hasattr(self._element_type, "__name__"):
175
+ _etype_name = self._element_type.__name__
176
+
177
+ output += f"number of elements: ({len(self)}) of type: {_etype_name}\n"
166
178
 
167
179
  output += f"unlist_data: {ut.print_truncated_list(self._unlist_data)}\n"
168
180
 
@@ -203,11 +215,11 @@ class CompressedList:
203
215
  ######>> names <<######
204
216
  #######################
205
217
 
206
- def get_names(self) -> Optional[ut.NamedList]:
218
+ def get_names(self) -> Optional[ut.Names]:
207
219
  """Get the names of list elements."""
208
220
  return self._partitioning.get_names()
209
221
 
210
- def set_names(self, names: List[str], in_place: bool = False) -> "CompressedList":
222
+ def set_names(self, names: Sequence[str], in_place: bool = False) -> "CompressedList":
211
223
  """Set the names of list elements.
212
224
 
213
225
  names:
@@ -227,7 +239,7 @@ class CompressedList:
227
239
  return output
228
240
 
229
241
  @property
230
- def names(self) -> Optional[ut.NamedList]:
242
+ def names(self) -> Optional[ut.Names]:
231
243
  """Alias for :py:attr:`~get_names`."""
232
244
  return self._partitioning.get_names()
233
245
 
@@ -460,7 +472,7 @@ class CompressedList:
460
472
 
461
473
  @classmethod
462
474
  def from_list(
463
- cls, lst: List[Any], names: Optional[Sequence[str]] = None, metadata: Optional[dict] = None
475
+ cls, lst: Any, names: Optional[Union[ut.Names, Sequence[str]]] = None, metadata: Optional[dict] = None
464
476
  ) -> "CompressedList":
465
477
  """Create a CompressedList from a regular list.
466
478
 
@@ -497,27 +509,40 @@ class CompressedList:
497
509
  ######>> coercions <<######
498
510
  ###########################
499
511
 
500
- def to_list(self) -> List[Any]:
512
+ def to_list(self) -> List[List[Any]]:
501
513
  """Convert to a regular Python list.
502
514
 
503
515
  Returns:
504
516
  A regular Python list with all elements.
505
517
  """
506
- return list(self)
518
+ result = []
519
+ for i in range(len(self)):
520
+ _subset = list(self[i])
521
+ if len(_subset) == 0:
522
+ _subset = [None]
523
+ result.append(_subset)
524
+
525
+ return result
507
526
 
508
- def unlist(self, use_names: bool = True) -> Any:
527
+ def as_list(self) -> List[List[Any]]:
528
+ """Alias to :py:meth:`~to_list`"""
529
+ return self.to_list()
530
+
531
+ def unlist(self, use_names: bool = False) -> Any:
509
532
  """Get the underlying unlisted data.
510
533
 
511
534
  Args:
512
535
  use_names:
513
536
  Whether to include names in the result if applicable.
514
537
 
515
- Currently not used.
516
-
517
538
  Returns:
518
539
  The unlisted data.
519
540
  """
520
- return self._unlist_data
541
+ return (
542
+ self._unlist_data
543
+ if use_names is False
544
+ else self._unlist_data.set_names(self.get_partitioning().get_names(), in_place=False)
545
+ )
521
546
 
522
547
  def relist(self, unlist_data: Any) -> "CompressedList":
523
548
  """Create a new `CompressedList` with the same partitioning but different data.
@@ -12,8 +12,10 @@ __copyright__ = "Jayaram Kancherla"
12
12
  __license__ = "MIT"
13
13
 
14
14
 
15
- class CompressedBiocFrameList(CompressedList):
16
- """CompressedList for BiocFrames."""
15
+ class CompressedSplitBiocFrameList(CompressedList):
16
+ """CompressedList for BiocFrames.
17
+
18
+ All BiocFrames are expected to have the same number and names of columns."""
17
19
 
18
20
  def __init__(
19
21
  self,
@@ -23,7 +25,7 @@ class CompressedBiocFrameList(CompressedList):
23
25
  metadata: Optional[dict] = None,
24
26
  **kwargs,
25
27
  ):
26
- """Initialize a CompressedBiocFrameList.
28
+ """Initialize a CompressedSplitBiocFrameList.
27
29
 
28
30
  Args:
29
31
  unlist_data:
@@ -50,9 +52,12 @@ class CompressedBiocFrameList(CompressedList):
50
52
 
51
53
  @classmethod
52
54
  def from_list(
53
- cls, lst: List[BiocFrame], names: Optional[Sequence[str]] = None, metadata: Optional[dict] = None
54
- ) -> "CompressedBiocFrameList":
55
- """Create a `CompressedBiocFrameList` from a regular list.
55
+ cls,
56
+ lst: List[BiocFrame],
57
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
58
+ metadata: Optional[dict] = None,
59
+ ) -> "CompressedSplitBiocFrameList":
60
+ """Create a `CompressedSplitBiocFrameList` from a regular list.
56
61
 
57
62
  This concatenates the list of `BiocFrame` objects.
58
63
 
@@ -60,6 +65,8 @@ class CompressedBiocFrameList(CompressedList):
60
65
  lst:
61
66
  List of `BiocFrame` objects.
62
67
 
68
+ Must have the same number and names of columns.
69
+
63
70
  names:
64
71
  Optional names for list elements.
65
72
 
@@ -106,21 +113,68 @@ class CompressedBiocFrameList(CompressedList):
106
113
  "Custom classes should implement their own `extract_range` method for slice operations"
107
114
  ) from e
108
115
 
116
+ ##########################
117
+ ######>> Printing <<######
118
+ ##########################
119
+
120
+ def __repr__(self) -> str:
121
+ """
122
+ Returns:
123
+ A string representation.
124
+ """
125
+ output = f"{type(self).__name__}(number_of_elements={len(self)}"
126
+ output += ", unlist_data=" + self._unlist_data.__repr__()
127
+ output += ", partitioning=" + self._partitioning.__repr__()
128
+ output += (
129
+ ", element_type=" + self._element_type.__name__
130
+ if not isinstance(self._element_type, str)
131
+ else self._element_type
132
+ )
133
+
134
+ if len(self._element_metadata) > 0:
135
+ output += ", element_metadata=" + ut.print_truncated_dict(self._element_metadata)
136
+
137
+ if len(self._metadata) > 0:
138
+ output += ", metadata=" + ut.print_truncated_dict(self._metadata)
139
+
140
+ output += ")"
141
+ return output
142
+
143
+ def __str__(self) -> str:
144
+ """
145
+ Returns:
146
+ A pretty-printed string containing the contents of this object.
147
+ """
148
+ output = f"class: {type(self).__name__}\n"
149
+
150
+ output += f"number of elements: ({len(self)}) of type: {self._element_type.__name__ if not isinstance(self._element_type, str) else self._element_type}\n"
151
+
152
+ output += f"unlist_data: {ut.print_truncated_list(self._unlist_data.get_column_names())}\n"
153
+
154
+ output += f"partitioning: {ut.print_truncated_list(self._partitioning)}\n"
155
+
156
+ output += f"element_metadata({str(len(self._element_metadata))}): {ut.print_truncated_list(list(self._element_metadata.keys()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
157
+ output += f"metadata({str(len(self._metadata))}): {ut.print_truncated_list(list(self._metadata.keys()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
158
+
159
+ return output
160
+
109
161
 
110
162
  @splitAsCompressedList.register
111
163
  def _(
112
164
  data: BiocFrame,
113
165
  groups_or_partitions: Union[list, Partitioning],
114
- names: Optional[Sequence[str]] = None,
166
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
115
167
  metadata: Optional[dict] = None,
116
- ) -> CompressedBiocFrameList:
168
+ ) -> CompressedSplitBiocFrameList:
117
169
  """Handle lists of BiocFrame objects."""
118
170
 
119
171
  partitioned_data, groups_or_partitions = _generic_register_helper(
120
172
  data=data, groups_or_partitions=groups_or_partitions, names=names
121
173
  )
122
174
 
123
- if not isinstance(partitioned_data, BiocFrame):
175
+ if not isinstance(partitioned_data, BiocFrame) and len(partitioned_data) != 0:
124
176
  partitioned_data = ut.relaxed_combine_rows(*partitioned_data)
125
177
 
126
- return CompressedBiocFrameList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
178
+ return CompressedSplitBiocFrameList(
179
+ unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata
180
+ )
@@ -58,7 +58,7 @@ class CompressedBooleanList(CompressedList):
58
58
  def _(
59
59
  data: ut.BooleanList,
60
60
  groups_or_partitions: Union[list, Partitioning],
61
- names: Optional[Sequence[str]] = None,
61
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
62
62
  metadata: Optional[dict] = None,
63
63
  ) -> CompressedBooleanList:
64
64
  """Handle lists of booleans."""
@@ -67,7 +67,7 @@ def _(
67
67
  data=data, groups_or_partitions=groups_or_partitions, names=names
68
68
  )
69
69
 
70
- if not isinstance(partitioned_data, ut.BooleanList):
70
+ if not isinstance(partitioned_data, ut.BooleanList) and len(partitioned_data) != 0:
71
71
  partitioned_data = ut.combine_sequences(*partitioned_data)
72
72
 
73
73
  return CompressedBooleanList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
@@ -58,7 +58,7 @@ class CompressedFloatList(CompressedList):
58
58
  def _(
59
59
  data: ut.FloatList,
60
60
  groups_or_partitions: Union[list, Partitioning],
61
- names: Optional[Sequence[str]] = None,
61
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
62
62
  metadata: Optional[dict] = None,
63
63
  ) -> CompressedFloatList:
64
64
  """Handle lists of floats."""
@@ -67,7 +67,7 @@ def _(
67
67
  data=data, groups_or_partitions=groups_or_partitions, names=names
68
68
  )
69
69
 
70
- if not isinstance(partitioned_data, ut.FloatList):
70
+ if not isinstance(partitioned_data, ut.FloatList) and len(partitioned_data) != 0:
71
71
  partitioned_data = ut.combine_sequences(*partitioned_data)
72
72
 
73
73
  return CompressedFloatList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
@@ -58,7 +58,7 @@ class CompressedIntegerList(CompressedList):
58
58
  def _(
59
59
  data: ut.IntegerList,
60
60
  groups_or_partitions: Union[list, Partitioning],
61
- names: Optional[Sequence[str]] = None,
61
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
62
62
  metadata: Optional[dict] = None,
63
63
  ) -> CompressedIntegerList:
64
64
  """Handle lists of integers."""
@@ -67,7 +67,7 @@ def _(
67
67
  data=data, groups_or_partitions=groups_or_partitions, names=names
68
68
  )
69
69
 
70
- if not isinstance(partitioned_data, ut.IntegerList):
70
+ if not isinstance(partitioned_data, ut.IntegerList) and len(partitioned_data) != 0:
71
71
  partitioned_data = ut.combine_sequences(*partitioned_data)
72
72
 
73
73
  return CompressedIntegerList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
@@ -44,11 +44,14 @@ class CompressedNumpyList(CompressedList):
44
44
  """
45
45
 
46
46
  if not isinstance(unlist_data, np.ndarray):
47
- try:
48
- warn("trying to concatenate/coerce 'unlist_data' to a `np.ndarray`..")
49
- unlist_data = np.concatenate(unlist_data)
50
- except Exception as e:
51
- raise TypeError("'unlist_data' must be an `np.ndarray`, provided ", type(unlist_data)) from e
47
+ if len(unlist_data) == 0:
48
+ unlist_data = np.asarray([])
49
+ else:
50
+ try:
51
+ warn("trying to concatenate/coerce 'unlist_data' to a `np.ndarray`..")
52
+ unlist_data = np.concatenate(unlist_data)
53
+ except Exception as e:
54
+ raise TypeError("'unlist_data' must be an `np.ndarray`, provided ", type(unlist_data)) from e
52
55
 
53
56
  super().__init__(
54
57
  unlist_data, partitioning, element_type=np.ndarray, element_metadata=element_metadata, metadata=metadata
@@ -56,7 +59,10 @@ class CompressedNumpyList(CompressedList):
56
59
 
57
60
  @classmethod
58
61
  def from_list(
59
- cls, lst: List[np.ndarray], names: Optional[Sequence[str]] = None, metadata: Optional[dict] = None
62
+ cls,
63
+ lst: List[np.ndarray],
64
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
65
+ metadata: Optional[dict] = None,
60
66
  ) -> "CompressedNumpyList":
61
67
  """
62
68
  Create a `CompressedNumpyList` from a list of NumPy vectors.
@@ -88,7 +94,7 @@ class CompressedNumpyList(CompressedList):
88
94
  def _(
89
95
  data: np.ndarray,
90
96
  groups_or_partitions: Union[list, Partitioning],
91
- names: Optional[Sequence[str]] = None,
97
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
92
98
  metadata: Optional[dict] = None,
93
99
  ) -> CompressedNumpyList:
94
100
  """Handle NumPy arrays."""
@@ -97,7 +103,7 @@ def _(
97
103
  data=data, groups_or_partitions=groups_or_partitions, names=names
98
104
  )
99
105
 
100
- if not isinstance(partitioned_data, np.ndarray):
106
+ if not isinstance(partitioned_data, np.ndarray) and len(partitioned_data) != 0:
101
107
  partitioned_data = ut.combine_sequences(*partitioned_data)
102
108
 
103
109
  return CompressedNumpyList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
@@ -24,7 +24,9 @@ class Partitioning:
24
24
  It keeps track of where each element begins and ends in the unlisted data.
25
25
  """
26
26
 
27
- def __init__(self, ends: Sequence[int], names: Optional[Sequence[str]] = None, validate: bool = True):
27
+ def __init__(
28
+ self, ends: Sequence[int], names: Optional[Union[ut.Names, Sequence[str]]] = None, validate: bool = True
29
+ ):
28
30
  """Initialize a Partitioning object.
29
31
 
30
32
  Args:
@@ -52,7 +54,9 @@ class Partitioning:
52
54
  _validate_names(names, len(ends))
53
55
 
54
56
  @classmethod
55
- def from_lengths(cls, lengths: Sequence[int], names: Optional[Sequence[str]] = None) -> "Partitioning":
57
+ def from_lengths(
58
+ cls, lengths: Sequence[int], names: Optional[Union[ut.Names, Sequence[str]]] = None
59
+ ) -> "Partitioning":
56
60
  """Create a Partitioning from a sequence of lengths.
57
61
 
58
62
  Args:
@@ -69,7 +73,7 @@ class Partitioning:
69
73
  return cls(ends, names)
70
74
 
71
75
  @classmethod
72
- def from_list(cls, lst: List, names: Optional[Sequence[str]] = None) -> "Partitioning":
76
+ def from_list(cls, lst: List, names: Optional[Union[ut.Names, Sequence[str]]] = None) -> "Partitioning":
73
77
  """Create a Partitioning from a list by using the lengths of each element.
74
78
 
75
79
  Args:
@@ -146,7 +150,7 @@ class Partitioning:
146
150
  """Return the lengths of each partition."""
147
151
  return self._ends - self._starts
148
152
 
149
- def element_lengths(self) -> int:
153
+ def element_lengths(self) -> np.ndarray:
150
154
  """Alias for :py:attr:`~get_element_lengths`."""
151
155
  return self.get_element_lengths()
152
156
 
@@ -216,7 +220,7 @@ class Partitioning:
216
220
  """Return the names of each partition."""
217
221
  return self._names
218
222
 
219
- def set_names(self, names: Optional[Sequence[str]], in_place: bool = False) -> "Partitioning":
223
+ def set_names(self, names: Optional[Union[ut.Names, Sequence[str]]], in_place: bool = False) -> "Partitioning":
220
224
  """Set the names of list elements.
221
225
 
222
226
  Args:
@@ -247,7 +251,7 @@ class Partitioning:
247
251
  return self.get_names()
248
252
 
249
253
  @names.setter
250
- def names(self, names: Optional[Sequence[str]]):
254
+ def names(self, names: Optional[Union[ut.Names, Sequence[str]]]):
251
255
  """Alias for :py:meth:`~set_names` with ``in_place = True``.
252
256
 
253
257
  As this mutates the original object, a warning is raised.
@@ -2,9 +2,9 @@ from collections import defaultdict
2
2
  from functools import singledispatch
3
3
  from typing import Any, List, Optional, Sequence, Tuple, Union
4
4
 
5
+ import biocutils as ut
5
6
  import numpy as np
6
7
 
7
- from .base import CompressedList
8
8
  from .partition import Partitioning
9
9
 
10
10
  __author__ = "Jayaram Kancherla"
@@ -13,7 +13,7 @@ __license__ = "MIT"
13
13
 
14
14
 
15
15
  def groups_to_partition(
16
- data: Any, groups: list, names: Optional[Sequence[str]] = None
16
+ data: Any, groups: list, names: Optional[Union[ut.Names, Sequence[str]]] = None
17
17
  ) -> Tuple[List[Any], Partitioning]:
18
18
  """Convert group membership vector to partitioned data and Partitioning object.
19
19
 
@@ -33,9 +33,13 @@ def groups_to_partition(
33
33
  if len(data) != len(groups):
34
34
  raise ValueError(f"Length of data ({len(data)}) must match length of groups ({len(groups)})")
35
35
 
36
+ group_idx_dict = defaultdict(list)
37
+ for idx, group in enumerate(groups):
38
+ group_idx_dict[group].append(idx)
39
+
36
40
  group_dict = defaultdict(list)
37
- for item, group in zip(data, groups):
38
- group_dict[group].append(item)
41
+ for key, val in group_idx_dict.items():
42
+ group_dict[key] = ut.subset(data, val)
39
43
 
40
44
  sorted_groups = sorted(group_dict.keys())
41
45
  partitioned_data = [group_dict[group] for group in sorted_groups]
@@ -50,7 +54,6 @@ def groups_to_partition(
50
54
  group_names = names
51
55
 
52
56
  partitioning = Partitioning.from_list(partitioned_data, group_names)
53
-
54
57
  return partitioned_data, partitioning
55
58
 
56
59
 
@@ -58,9 +61,9 @@ def groups_to_partition(
58
61
  def splitAsCompressedList(
59
62
  data: Any,
60
63
  groups_or_partitions: Union[list, Partitioning],
61
- names: Optional[Sequence[str]] = None,
64
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
62
65
  metadata: Optional[dict] = None,
63
- ) -> CompressedList:
66
+ ) -> Any:
64
67
  """Generic function to split data into an appropriate `CompressedList` subclass.
65
68
 
66
69
  This function can work in two modes:
@@ -85,14 +88,38 @@ def splitAsCompressedList(
85
88
  An appropriate `CompressedList` subclass instance.
86
89
  """
87
90
  element_type = type(data)
88
- raise NotImplementedError(f"No `splitAsCompressedList` dispatcher found for element type {element_type}")
91
+ try:
92
+ if isinstance(groups_or_partitions, Partitioning):
93
+ partitioned_data = []
94
+ for i in range(len(groups_or_partitions)):
95
+ start, end = groups_or_partitions.get_partition_range(i)
96
+ _part = data[start:end]
97
+ partitioned_data.append(_part)
98
+ else:
99
+ if isinstance(groups_or_partitions, np.ndarray):
100
+ groups_or_partitions = groups_or_partitions.tolist()
101
+
102
+ group_idx_dict = defaultdict(list)
103
+ for idx, group in enumerate(groups_or_partitions):
104
+ group_idx_dict[group].append(idx)
105
+
106
+ group_dict = defaultdict(list)
107
+ for key, val in group_idx_dict.items():
108
+ group_dict[key] = ut.subset(data, val)
109
+
110
+ sorted_groups = sorted(group_dict.keys())
111
+ partitioned_data = [group_dict[group] for group in sorted_groups]
112
+
113
+ return partitioned_data
114
+ except Exception as e:
115
+ raise NotImplementedError(f"No `splitAsCompressedList` dispatcher found for element type {element_type}") from e
89
116
 
90
117
 
91
118
  def _generic_register_helper(data, groups_or_partitions, names=None):
92
119
  if groups_or_partitions is None:
93
120
  raise ValueError("'groups_or_paritions' cannot be 'None'.")
94
121
 
95
- if not data:
122
+ if data is None:
96
123
  raise ValueError("'data' cannot be empty.")
97
124
 
98
125
  if isinstance(groups_or_partitions, Partitioning):
@@ -107,9 +134,12 @@ def _generic_register_helper(data, groups_or_partitions, names=None):
107
134
  # partitioned_data.append(data[start:end])
108
135
  partitioned_data = data
109
136
  elif isinstance(groups_or_partitions, (list, np.ndarray)):
137
+ if isinstance(groups_or_partitions, np.ndarray):
138
+ groups_or_partitions = groups_or_partitions.tolist()
139
+
110
140
  partitioned_data, groups_or_partitions = groups_to_partition(data, groups=groups_or_partitions, names=names)
111
141
 
112
- if len(partitioned_data) == 0:
142
+ if partitioned_data is None:
113
143
  raise ValueError("No data after grouping")
114
144
  else:
115
145
  raise ValueError("'groups_or_paritions' must be a group vector or a Partition object.")
@@ -61,16 +61,16 @@ class CompressedCharacterList(CompressedStringList):
61
61
  def _(
62
62
  data: ut.StringList,
63
63
  groups_or_partitions: Union[list, Partitioning],
64
- names: Optional[Sequence[str]] = None,
64
+ names: Optional[Union[ut.Names, Sequence[str]]] = None,
65
65
  metadata: Optional[dict] = None,
66
66
  ) -> CompressedStringList:
67
- """Handle lists of floats."""
67
+ """Handle lists of strings."""
68
68
 
69
69
  partitioned_data, groups_or_partitions = _generic_register_helper(
70
70
  data=data, groups_or_partitions=groups_or_partitions, names=names
71
71
  )
72
72
 
73
- if not isinstance(partitioned_data, ut.StringList):
73
+ if not isinstance(partitioned_data, ut.StringList) and len(partitioned_data) != 0:
74
74
  partitioned_data = ut.combine_sequences(*partitioned_data)
75
75
 
76
76
  return CompressedStringList(unlist_data=partitioned_data, partitioning=groups_or_partitions, metadata=metadata)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compressed-lists
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Memory-efficient container for list-like objects
5
5
  Home-page: https://github.com/biocpy/compressed-lists
6
6
  Author: Jayaram Kancherla
@@ -41,6 +41,7 @@ src/compressed_lists.egg-info/not-zip-safe
41
41
  src/compressed_lists.egg-info/requires.txt
42
42
  src/compressed_lists.egg-info/top_level.txt
43
43
  tests/conftest.py
44
+ tests/test_base.py
44
45
  tests/test_comp_biocframe.py
45
46
  tests/test_comp_bool.py
46
47
  tests/test_comp_custom.py
@@ -49,4 +50,5 @@ tests/test_comp_int.py
49
50
  tests/test_comp_numpy.py
50
51
  tests/test_comp_str.py
51
52
  tests/test_generics.py
52
- tests/test_partitioning.py
53
+ tests/test_partitioning.py
54
+ tests/test_type_validations.py
@@ -0,0 +1,132 @@
1
+ from copy import copy, deepcopy
2
+
3
+ import pytest
4
+
5
+ from compressed_lists import CompressedList
6
+
7
+ __author__ = "Jayaram Kancherla"
8
+ __copyright__ = "Jayaram Kancherla"
9
+ __license__ = "MIT"
10
+
11
+
12
+ @pytest.fixture
13
+ def base_list_data():
14
+ return [[1, 2], [3], [4, 5, 6]]
15
+
16
+
17
+ @pytest.fixture
18
+ def base_list(base_list_data):
19
+ names = ["A", "B", "C"]
20
+ return CompressedList.from_list(base_list_data, names)
21
+
22
+
23
+ def test_base_empty_creation():
24
+ cl_empty = CompressedList.from_list([])
25
+ assert len(cl_empty) == 0
26
+ assert len(cl_empty.unlist_data) == 0
27
+ assert list(cl_empty.get_element_lengths()) == []
28
+ assert cl_empty.to_list() == []
29
+
30
+
31
+ def test_base_list_of_empty():
32
+ cl_list_empty = CompressedList.from_list([[], [], []])
33
+ assert len(cl_list_empty) == 3
34
+ assert len(cl_list_empty.unlist_data) == 0
35
+ assert list(cl_list_empty.get_element_lengths()) == [0, 0, 0]
36
+ assert list(cl_list_empty[0]) == []
37
+ assert list(cl_list_empty[1]) == []
38
+ assert list(cl_list_empty[2]) == []
39
+
40
+
41
+ def test_base_set_names(base_list):
42
+ new_names = ["X", "Y", "Z"]
43
+
44
+ cl_new_names = base_list.set_names(new_names, in_place=False)
45
+ assert list(base_list.names) == ["A", "B", "C"] # Original is unchanged
46
+ assert list(cl_new_names.names) == new_names
47
+
48
+ with pytest.warns(UserWarning, match="Setting property 'names'"):
49
+ base_list.names = new_names
50
+ assert list(base_list.names) == new_names
51
+
52
+
53
+ def test_base_set_unlist_data(base_list):
54
+ new_data = [10, 20, 30, 40, 50, 60]
55
+ assert len(new_data) == len(base_list.unlist_data)
56
+
57
+ cl_new_data = base_list.set_unlist_data(new_data, in_place=False)
58
+ assert base_list.unlist_data == [1, 2, 3, 4, 5, 6] # Original is unchanged
59
+ assert cl_new_data.unlist_data == new_data
60
+ assert list(cl_new_data[0]) == [10, 20]
61
+
62
+ with pytest.warns(UserWarning, match="Setting property 'unlist_data'"):
63
+ base_list.unlist_data = new_data
64
+ assert base_list.unlist_data == new_data
65
+ assert list(base_list[1]) == [30]
66
+
67
+
68
+ def test_base_set_unlist_data_error(base_list):
69
+ with pytest.raises(ValueError, match="Length of 'unlist_data'"):
70
+ base_list.set_unlist_data([1, 2, 3], in_place=False)
71
+
72
+
73
+ def test_base_metadata(base_list):
74
+ meta = {"source": "test"}
75
+ cl_meta = base_list.set_metadata(meta, in_place=False)
76
+ assert base_list.metadata == {}
77
+ assert cl_meta.metadata == {"source": "test"}
78
+
79
+ with pytest.warns(UserWarning, match="Setting property 'metadata'"):
80
+ base_list.metadata = meta
81
+ assert base_list.metadata == {"source": "test"}
82
+
83
+ el_meta = {"info": "details"}
84
+ cl_el_meta = base_list.set_element_metadata(el_meta, in_place=False)
85
+ assert base_list.element_metadata == {}
86
+ assert cl_el_meta.element_metadata == {"info": "details"}
87
+
88
+ with pytest.warns(UserWarning, match="Setting property 'element_metadata'"):
89
+ base_list.element_metadata = el_meta
90
+ assert base_list.element_metadata == {"info": "details"}
91
+
92
+
93
+ def test_base_copying(base_list):
94
+ cl_copy = copy(base_list)
95
+ assert cl_copy is not base_list
96
+ assert cl_copy.unlist_data is base_list.unlist_data
97
+ assert cl_copy.get_partitioning() is base_list.get_partitioning()
98
+
99
+ cl_deepcopy = deepcopy(base_list)
100
+ assert cl_deepcopy is not base_list
101
+ assert cl_deepcopy.unlist_data is not base_list.unlist_data
102
+ assert cl_deepcopy.unlist_data == base_list.unlist_data
103
+ assert cl_deepcopy.get_partitioning() is not base_list.get_partitioning()
104
+ assert list(cl_deepcopy.get_partitioning().get_ends()) == list(base_list.get_partitioning().get_ends())
105
+
106
+
107
+ def test_base_repr_str(base_list):
108
+ assert isinstance(repr(base_list), str)
109
+ assert "CompressedList" in repr(base_list)
110
+ assert "number_of_elements=3" in repr(base_list)
111
+
112
+ assert isinstance(str(base_list), str)
113
+ assert "class: CompressedList" in str(base_list)
114
+ assert "number of elements: (3)" in str(base_list)
115
+
116
+
117
+ def test_base_extract_subset_edge_cases(base_list, base_list_data):
118
+ sub_empty = base_list.extract_subset([])
119
+ assert len(sub_empty) == 0
120
+ assert len(sub_empty.unlist_data) == 0
121
+
122
+ sub_dup = base_list.extract_subset([0, 1, 0])
123
+ assert len(sub_dup) == 3
124
+ assert list(sub_dup.names) == ["A", "B", "A"]
125
+ assert sub_dup.to_list() == [base_list_data[0], base_list_data[1], base_list_data[0]]
126
+ assert sub_dup.unlist_data == [1, 2, 3, 1, 2]
127
+
128
+ sub_order = base_list.extract_subset([2, 0])
129
+ assert len(sub_order) == 2
130
+ assert list(sub_order.names) == ["C", "A"]
131
+ assert sub_order.to_list() == [base_list_data[2], base_list_data[0]]
132
+ assert sub_order.unlist_data == [4, 5, 6, 1, 2]
@@ -1,8 +1,8 @@
1
+ import biocutils as ut
1
2
  import pytest
2
3
  from biocframe import BiocFrame
3
- import biocutils as ut
4
4
 
5
- from compressed_lists import CompressedBiocFrameList, Partitioning, CompressedStringList
5
+ from compressed_lists import CompressedSplitBiocFrameList, CompressedStringList, Partitioning, splitAsCompressedList
6
6
 
7
7
  __author__ = "Jayaram Kancherla"
8
8
  __copyright__ = "Jayaram Kancherla"
@@ -20,9 +20,9 @@ def frame_data():
20
20
 
21
21
 
22
22
  def test_creation(frame_data):
23
- frame_list = CompressedBiocFrameList(frame_data, partitioning=Partitioning.from_lengths([1, 2]))
23
+ frame_list = CompressedSplitBiocFrameList(frame_data, partitioning=Partitioning.from_lengths([1, 2]))
24
24
 
25
- assert isinstance(frame_list, CompressedBiocFrameList)
25
+ assert isinstance(frame_list, CompressedSplitBiocFrameList)
26
26
  assert len(frame_list) == 2
27
27
  assert isinstance(frame_list.unlist_data, BiocFrame)
28
28
  assert len(frame_list.get_unlist_data()) == 3
@@ -37,8 +37,22 @@ def test_bframe_typed_list_column():
37
37
  "symbol": ["MAP1A", "BIN1", "ESR1"],
38
38
  }
39
39
  )
40
- frame_list = CompressedBiocFrameList(bframe, partitioning=Partitioning.from_lengths([1, 2]))
40
+ frame_list = CompressedSplitBiocFrameList(bframe, partitioning=Partitioning.from_lengths([1, 2]))
41
41
 
42
42
  ens_col = frame_list["ensembl"]
43
43
  assert isinstance(ens_col, CompressedStringList)
44
44
  assert len(ens_col) == 2
45
+
46
+
47
+ def test_split_biocframe(frame_data):
48
+ frame_data.set_column("groups", [0, 0, 1], in_place=True)
49
+ print(frame_data)
50
+ clist = splitAsCompressedList(frame_data, groups_or_partitions=frame_data.get_column("groups"))
51
+
52
+ assert isinstance(clist, CompressedSplitBiocFrameList)
53
+
54
+ val = clist.__repr__()
55
+ assert isinstance(val, str)
56
+
57
+ val = clist.__str__()
58
+ assert isinstance(val, str)
@@ -88,13 +88,13 @@ def test_getitem_by_slice(int_list):
88
88
  def test_iteration(int_list, int_data):
89
89
  items = list(int_list)
90
90
  for i, lst in enumerate(items):
91
- assert np.allclose(list(lst), int_data[i])
91
+ assert np.allclose(lst, int_data[i])
92
92
 
93
93
 
94
94
  def test_to_list(int_list, int_data):
95
95
  regular_list = int_list.to_list()
96
96
  for i, lst in enumerate(regular_list):
97
- assert np.allclose(list(lst), int_data[i])
97
+ assert np.allclose(lst, int_data[i])
98
98
 
99
99
 
100
100
  def test_unlist(int_list):
@@ -0,0 +1,86 @@
1
+ import biocutils as ut
2
+ import numpy as np
3
+ import pytest
4
+
5
+ from compressed_lists import (
6
+ CompressedFloatList,
7
+ CompressedIntegerList,
8
+ CompressedNumpyList,
9
+ Partitioning,
10
+ splitAsCompressedList,
11
+ )
12
+ from compressed_lists.split_generic import _generic_register_helper, groups_to_partition
13
+
14
+ __author__ = "Jayaram Kancherla"
15
+ __copyright__ = "Jayaram Kancherla"
16
+ __license__ = "MIT"
17
+
18
+
19
+ def test_groups():
20
+ float_vec = ut.FloatList([1.1, 1.2, 2.1, 2.2, 2.3, 3.0])
21
+ groups = [1, 2, 3, 1, 2, 3]
22
+
23
+ clist = splitAsCompressedList(float_vec, groups_or_partitions=groups)
24
+
25
+ assert isinstance(clist, CompressedFloatList)
26
+
27
+
28
+ def test_partitions():
29
+ int_list = splitAsCompressedList(
30
+ ut.IntegerList([1, 2, 3, 4, 5, 6, 7, 8, 9]), groups_or_partitions=Partitioning(ends=[3, 5, 9])
31
+ )
32
+
33
+ assert isinstance(int_list, CompressedIntegerList)
34
+
35
+
36
+ def test_groups_to_partition_value_error():
37
+ with pytest.raises(ValueError, match="must match length of groups"):
38
+ groups_to_partition([1, 2, 3], [1, 2], None)
39
+
40
+
41
+ def test_groups_to_partition_empty():
42
+ data = []
43
+ groups = []
44
+ part_data, part = groups_to_partition(data, groups)
45
+ assert part_data == []
46
+ assert len(part) == 0
47
+
48
+
49
+ def test_splitAsCompressedList_unsupported_type():
50
+ class UnregisteredType:
51
+ def __init__(self):
52
+ self.data = [1, 2]
53
+
54
+ def __len__(self):
55
+ return len(self.data)
56
+
57
+ def __getitem__(self, i):
58
+ return self.data[i]
59
+
60
+ data = UnregisteredType()
61
+ with pytest.raises(NotImplementedError, match="No `splitAsCompressedList` dispatcher found"):
62
+ splitAsCompressedList(data, groups_or_partitions=[0, 0])
63
+
64
+
65
+ def test_splitAsCompressedList_empty():
66
+ data_int = ut.IntegerList([])
67
+ groups_int = []
68
+ clist_int = splitAsCompressedList(data_int, groups_int)
69
+ assert isinstance(clist_int, CompressedIntegerList)
70
+ assert len(clist_int) == 0
71
+ assert len(clist_int.unlist_data) == 0
72
+
73
+ data_np = np.array([])
74
+ groups_np = []
75
+ clist_np = splitAsCompressedList(data_np, groups_np)
76
+ assert isinstance(clist_np, CompressedNumpyList)
77
+ assert len(clist_np) == 0
78
+ assert len(clist_np.unlist_data) == 0
79
+
80
+
81
+ def test_generic_register_helper_errors():
82
+ with pytest.raises(ValueError, match="'groups_or_paritions' cannot be 'None'"):
83
+ _generic_register_helper([1, 2, 3], None)
84
+
85
+ with pytest.raises(ValueError, match="'groups_or_paritions' must be a group vector or a Partition object"):
86
+ _generic_register_helper([1, 2, 3], {"a": 1})
@@ -78,3 +78,41 @@ def test_getitem():
78
78
 
79
79
  with pytest.raises(TypeError):
80
80
  part["invalid"]
81
+
82
+
83
+ def test_partitioning_empty():
84
+ part = Partitioning([])
85
+ assert len(part) == 0
86
+ assert part.nobj() == 0
87
+ assert list(part.get_element_lengths()) == []
88
+ assert part.get_names() is None
89
+
90
+
91
+ def test_partitioning_from_list_non_sequence():
92
+ # The implementation checks for __len__ or assumes 1
93
+ lst = [1, [2, 3], "foo", (4, 5, 6)]
94
+ part = Partitioning.from_list(lst)
95
+ assert list(part.get_element_lengths()) == [1, 2, 3, 3]
96
+ assert list(part.ends) == [1, 3, 6, 9]
97
+
98
+
99
+ def test_partitioning_getitem_slices():
100
+ part = Partitioning.from_lengths([2, 3, 5, 1])
101
+
102
+ assert part[:] == [(0, 2), (2, 5), (5, 10), (10, 11)]
103
+ assert part[-2:] == [(5, 10), (10, 11)]
104
+ assert part[::2] == [(0, 2), (5, 10)]
105
+
106
+
107
+ def test_partitioning_set_names_inplace():
108
+ part = Partitioning.from_lengths([2, 3], names=["A", "B"])
109
+
110
+ part_new = part.set_names(["X", "Y"], in_place=False)
111
+ assert list(part.names) == ["A", "B"]
112
+ assert list(part_new.names) == ["X", "Y"]
113
+
114
+ part.set_names(["X", "Y"], in_place=True)
115
+ assert list(part.names) == ["X", "Y"]
116
+
117
+ with pytest.raises(ValueError, match="Length of names must match"):
118
+ part.set_names(["X"], in_place=True)
@@ -0,0 +1,32 @@
1
+ import biocutils as ut
2
+ import pytest
3
+
4
+ from compressed_lists import (
5
+ CompressedBooleanList,
6
+ CompressedFloatList,
7
+ CompressedIntegerList,
8
+ CompressedStringList,
9
+ Partitioning,
10
+ )
11
+
12
+ __author__ = "Jayaram Kancherla"
13
+ __copyright__ = "Jayaram Kancherla"
14
+ __license__ = "MIT"
15
+
16
+
17
+ @pytest.mark.parametrize(
18
+ "Cls, data, unlist_type",
19
+ [
20
+ (CompressedIntegerList, [1, 2, 3], ut.IntegerList),
21
+ (CompressedFloatList, [1.1, 2.2], ut.FloatList),
22
+ (CompressedBooleanList, [True, False, True], ut.BooleanList),
23
+ (CompressedStringList, ["a", "b", "c"], ut.StringList),
24
+ ],
25
+ )
26
+ def test_coercion_warning(Cls, data, unlist_type):
27
+ part = Partitioning.from_lengths([len(data)])
28
+ with pytest.warns(UserWarning, match="trying to coerce"):
29
+ clist = Cls(data, part)
30
+
31
+ assert isinstance(clist.unlist_data, unlist_type)
32
+ assert list(clist.unlist_data) == data
@@ -1,10 +0,0 @@
1
- # Changelog
2
-
3
- ## Version 0.2.0
4
-
5
- - Major changes to the package; Switch to typed lists from the biocutils package.
6
-
7
- ## Version 0.1.0 - 0.1.1
8
-
9
- - Initial implementation of various classes - Partitioning and CompressedLists.
10
- - Udpate documentation, tutorial and tests.
@@ -1,24 +0,0 @@
1
- import biocutils as ut
2
-
3
- from compressed_lists import CompressedFloatList, CompressedIntegerList, Partitioning, splitAsCompressedList
4
-
5
- __author__ = "Jayaram Kancherla"
6
- __copyright__ = "Jayaram Kancherla"
7
- __license__ = "MIT"
8
-
9
-
10
- def test_groups():
11
- float_vec = ut.FloatList([1.1, 1.2, 2.1, 2.2, 2.3, 3.0])
12
- groups = [1, 2, 3, 1, 2, 3]
13
-
14
- clist = splitAsCompressedList(float_vec, groups_or_partitions=groups)
15
-
16
- assert isinstance(clist, CompressedFloatList)
17
-
18
-
19
- def test_partitions():
20
- int_list = splitAsCompressedList(
21
- ut.IntegerList([1, 2, 3, 4, 5, 6, 7, 8, 9]), groups_or_partitions=Partitioning(ends=[3, 5, 9])
22
- )
23
-
24
- assert isinstance(int_list, CompressedIntegerList)