compressed-lists 0.4.2__tar.gz → 0.4.4__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 (55) hide show
  1. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/CHANGELOG.md +2 -1
  2. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/PKG-INFO +3 -3
  3. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/setup.cfg +2 -2
  4. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/base.py +66 -22
  5. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/biocframe_list.py +2 -3
  6. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/PKG-INFO +3 -3
  7. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/requires.txt +2 -2
  8. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_base.py +6 -6
  9. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_biocframe.py +0 -1
  10. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_bool.py +1 -1
  11. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_float.py +1 -1
  12. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_int.py +1 -1
  13. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_str.py +1 -1
  14. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.coveragerc +0 -0
  15. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.github/workflows/publish-pypi.yml +0 -0
  16. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.github/workflows/run-tests.yml +0 -0
  17. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.gitignore +0 -0
  18. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.pre-commit-config.yaml +0 -0
  19. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/.readthedocs.yml +0 -0
  20. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/AUTHORS.md +0 -0
  21. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/CONTRIBUTING.md +0 -0
  22. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/LICENSE.txt +0 -0
  23. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/README.md +0 -0
  24. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/Makefile +0 -0
  25. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/_static/.gitignore +0 -0
  26. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/authors.md +0 -0
  27. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/changelog.md +0 -0
  28. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/conf.py +0 -0
  29. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/contributing.md +0 -0
  30. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/index.md +0 -0
  31. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/license.md +0 -0
  32. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/readme.md +0 -0
  33. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/requirements.txt +0 -0
  34. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/docs/tutorial.md +0 -0
  35. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/pyproject.toml +0 -0
  36. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/setup.py +0 -0
  37. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/__init__.py +0 -0
  38. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/bool_list.py +0 -0
  39. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/float_list.py +0 -0
  40. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/integer_list.py +0 -0
  41. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/numpy_list.py +0 -0
  42. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/partition.py +0 -0
  43. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/split_generic.py +0 -0
  44. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists/string_list.py +0 -0
  45. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/SOURCES.txt +0 -0
  46. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/dependency_links.txt +0 -0
  47. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/not-zip-safe +0 -0
  48. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/src/compressed_lists.egg-info/top_level.txt +0 -0
  49. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/conftest.py +0 -0
  50. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_custom.py +0 -0
  51. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_comp_numpy.py +0 -0
  52. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_generics.py +0 -0
  53. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_partitioning.py +0 -0
  54. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tests/test_type_validations.py +0 -0
  55. {compressed_lists-0.4.2 → compressed_lists-0.4.4}/tox.ini +0 -0
@@ -1,11 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## Version 0.4.0 - 0.4.2
3
+ ## Version 0.4.0 - 0.4.4
4
4
 
5
5
  - Classes extend `BiocObject` from biocutils. `metadata` is a named list.
6
6
  - Update actions to run from 3.10-3.14
7
7
  - Support empty compressed list objects of size `n`.
8
8
  - Implement combine generic for compressed lists.
9
+ - element metadata slot is a `BiocFrame`.
9
10
 
10
11
  ## Version 0.3.0
11
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compressed-lists
3
- Version: 0.4.2
3
+ Version: 0.4.4
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
@@ -14,9 +14,9 @@ Requires-Python: >=3.9
14
14
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
15
  License-File: LICENSE.txt
16
16
  Requires-Dist: importlib-metadata; python_version < "3.8"
17
- Requires-Dist: biocutils>=0.3.1
17
+ Requires-Dist: biocutils>=0.3.3
18
18
  Requires-Dist: numpy
19
- Requires-Dist: biocframe>=0.7.1
19
+ Requires-Dist: biocframe>=0.7.2
20
20
  Provides-Extra: testing
21
21
  Requires-Dist: setuptools; extra == "testing"
22
22
  Requires-Dist: pytest; extra == "testing"
@@ -24,9 +24,9 @@ package_dir =
24
24
  python_requires = >=3.9
25
25
  install_requires =
26
26
  importlib-metadata; python_version<"3.8"
27
- biocutils>=0.3.1
27
+ biocutils>=0.3.3
28
28
  numpy
29
- biocframe>=0.7.1
29
+ biocframe>=0.7.2
30
30
 
31
31
  [options.packages.find]
32
32
  where = src
@@ -4,6 +4,7 @@ from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Unio
4
4
  from warnings import warn
5
5
 
6
6
  import biocutils as ut
7
+ from biocframe import BiocFrame
7
8
  import numpy as np
8
9
 
9
10
  from .partition import Partitioning
@@ -13,6 +14,31 @@ __copyright__ = "Jayaram Kancherla"
13
14
  __license__ = "MIT"
14
15
 
15
16
 
17
+ def is_pandas(x: Any) -> bool:
18
+ """Check if ``x`` is a :py:class:`~pandas.DataFrame`.
19
+
20
+ Args:
21
+ x:
22
+ Any object.
23
+
24
+ Returns:
25
+ True if ``x`` is a :py:class:`~pandas.DataFrame`.
26
+ """
27
+ if hasattr(x, "dtypes"):
28
+ return True
29
+
30
+ return False
31
+
32
+
33
+ def _sanitize_frame(frame, num_rows: int):
34
+ frame = frame if frame is not None else BiocFrame({}, number_of_rows=num_rows)
35
+
36
+ if is_pandas(frame):
37
+ frame = BiocFrame.from_pandas(frame)
38
+
39
+ return frame
40
+
41
+
16
42
  def _validate_data_and_partitions(unlist_data, partition):
17
43
  if len(unlist_data) != partition.nobj():
18
44
  raise ValueError(
@@ -33,7 +59,7 @@ class CompressedList(ut.BiocObject):
33
59
  unlist_data: Any,
34
60
  partitioning: Partitioning,
35
61
  element_type: Any = None,
36
- element_metadata: Optional[dict] = None,
62
+ element_metadata: Optional[BiocFrame] = None,
37
63
  metadata: Optional[Union[Dict[str, Any], ut.NamedList]] = None,
38
64
  _validate: bool = True,
39
65
  ):
@@ -64,7 +90,7 @@ class CompressedList(ut.BiocObject):
64
90
  self._unlist_data = unlist_data
65
91
  self._partitioning = partitioning
66
92
  self._element_type = element_type
67
- self._element_metadata = element_metadata or {}
93
+ self._element_metadata = _sanitize_frame(element_metadata, len(partitioning))
68
94
 
69
95
  if _validate:
70
96
  _validate_data_and_partitions(self._unlist_data, self._partitioning)
@@ -93,6 +119,7 @@ class CompressedList(ut.BiocObject):
93
119
  element_type=_elem_type_copy,
94
120
  element_metadata=_elem_metadata_copy,
95
121
  metadata=_metadata_copy,
122
+ _validate=False,
96
123
  )
97
124
 
98
125
  def __copy__(self):
@@ -107,6 +134,7 @@ class CompressedList(ut.BiocObject):
107
134
  element_type=self._element_type,
108
135
  element_metadata=self._element_metadata,
109
136
  metadata=self._metadata,
137
+ _validate=False,
110
138
  )
111
139
 
112
140
  def copy(self):
@@ -150,8 +178,7 @@ class CompressedList(ut.BiocObject):
150
178
  _etype_name = self._element_type.__name__
151
179
  output += ", element_type=" + _etype_name
152
180
 
153
- if len(self._element_metadata) > 0:
154
- output += ", element_metadata=" + ut.print_truncated_dict(self._element_metadata)
181
+ output += ", element_metadata=" + self._element_metadata.__repr__()
155
182
 
156
183
  if len(self._metadata) > 0:
157
184
  output += ", metadata=" + ut.print_truncated_dict(self._metadata)
@@ -178,7 +205,7 @@ class CompressedList(ut.BiocObject):
178
205
 
179
206
  output += f"partitioning: {ut.print_truncated_list(self._partitioning)}\n"
180
207
 
181
- 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"
208
+ output += f"element_metadata({str(len(self._element_metadata))} rows): {ut.print_truncated_list(list(self._element_metadata.get_column_names()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
182
209
  output += f"metadata({str(len(self._metadata))}): {ut.print_truncated_list(list(self._metadata.keys()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
183
210
 
184
211
  return output
@@ -303,14 +330,14 @@ class CompressedList(ut.BiocObject):
303
330
  ######>> element metadata <<#######
304
331
  ###################################
305
332
 
306
- def get_element_metadata(self) -> dict:
333
+ def get_element_metadata(self) -> BiocFrame:
307
334
  """
308
335
  Returns:
309
336
  Dictionary of metadata for each element in this object.
310
337
  """
311
338
  return self._element_metadata
312
339
 
313
- def set_element_metadata(self, element_metadata: dict, in_place: bool = False) -> CompressedList:
340
+ def set_element_metadata(self, element_metadata: BiocFrame, in_place: bool = False) -> CompressedList:
314
341
  """Set new element metadata.
315
342
 
316
343
  Args:
@@ -324,19 +351,20 @@ class CompressedList(ut.BiocObject):
324
351
  A modified ``CompressedList`` object, either as a copy of the original
325
352
  or as a reference to the (in-place-modified) original.
326
353
  """
327
- if not isinstance(element_metadata, dict):
328
- raise TypeError(f"`element_metadata` must be a dictionary, provided {type(element_metadata)}.")
354
+ if not isinstance(element_metadata, BiocFrame):
355
+ raise TypeError(f"`element_metadata` must be a BiocFrame, provided {type(element_metadata)}.")
356
+
329
357
  output = self._define_output(in_place)
330
- output._element_metadata = element_metadata
358
+ output._element_metadata = _sanitize_frame(element_metadata, len(self._partitioning))
331
359
  return output
332
360
 
333
361
  @property
334
- def element_metadata(self) -> dict:
362
+ def element_metadata(self) -> BiocFrame:
335
363
  """Alias for :py:attr:`~get_element_metadata`."""
336
364
  return self.get_element_metadata()
337
365
 
338
366
  @element_metadata.setter
339
- def element_metadata(self, element_metadata: dict):
367
+ def element_metadata(self, element_metadata: BiocFrame):
340
368
  """Alias for :py:attr:`~set_element_metadata` with ``in_place = True``.
341
369
 
342
370
  As this mutates the original object, a warning is raised.
@@ -378,7 +406,10 @@ class CompressedList(ut.BiocObject):
378
406
  return self.extract_range(start, end)
379
407
 
380
408
  # slices
381
- elif isinstance(key, slice):
409
+ elif isinstance(key, (range, slice)):
410
+ if isinstance(key, range):
411
+ key = slice(key.start, key.stop, key.step)
412
+
382
413
  indices = range(*key.indices(len(self)))
383
414
  result = []
384
415
  for i in indices:
@@ -531,6 +562,10 @@ class CompressedList(ut.BiocObject):
531
562
  Returns:
532
563
  A new CompressedList with only the selected elements.
533
564
  """
565
+ print("here", indices, type(indices))
566
+ if isinstance(indices, np.ndarray):
567
+ indices = indices.tolist()
568
+
534
569
  # Validate indices
535
570
  for i in indices:
536
571
  if i < 0 or i >= len(self):
@@ -544,23 +579,32 @@ class CompressedList(ut.BiocObject):
544
579
  new_partitioning = Partitioning.from_lengths(new_lengths, new_names)
545
580
 
546
581
  # Extract data
547
- new_data = []
582
+ _new_data = []
548
583
  for i in indices:
549
584
  start, end = self._partitioning.get_partition_range(i)
550
- if isinstance(self._unlist_data, np.ndarray):
551
- new_data.append(self._unlist_data[start:end])
552
- else:
553
- new_data.extend(self._unlist_data[start:end])
554
-
555
- if isinstance(self._unlist_data, np.ndarray):
556
- new_data = np.concatenate(new_data)
585
+ _subset = ut.subset_sequence(self._unlist_data, [j for j in range(start, end)])
586
+ _new_data.append(_subset)
587
+ # if isinstance(self._unlist_data, np.ndarray):
588
+ # new_data.append(self._unlist_data[start:end])
589
+ # else:
590
+ # new_data.extend(self._unlist_data[start:end])
591
+
592
+ # if isinstance(self._unlist_data, np.ndarray):
593
+ # new_data = np.concatenate(new_data)
594
+
595
+ if len(_new_data) == 1:
596
+ new_data = _new_data[0]
597
+ elif len(_new_data) > 0:
598
+ new_data = ut.combine_sequences(*_new_data)
599
+ else:
600
+ new_data = []
557
601
 
558
602
  current_class_const = type(self)
559
603
  return current_class_const(
560
604
  new_data,
561
605
  new_partitioning,
562
606
  element_type=self._element_type,
563
- element_metadata={k: v for k, v in self._element_metadata.items() if k in indices},
607
+ element_metadata=self._element_metadata[indices,],
564
608
  metadata=self._metadata.copy(),
565
609
  )
566
610
 
@@ -133,8 +133,7 @@ class CompressedSplitBiocFrameList(CompressedList):
133
133
  else self._element_type
134
134
  )
135
135
 
136
- if len(self._element_metadata) > 0:
137
- output += ", element_metadata=" + ut.print_truncated_dict(self._element_metadata)
136
+ output += ", element_metadata=" + self._element_metadata.__repr__()
138
137
 
139
138
  if len(self._metadata) > 0:
140
139
  output += ", metadata=" + ut.print_truncated_dict(self._metadata)
@@ -155,7 +154,7 @@ class CompressedSplitBiocFrameList(CompressedList):
155
154
 
156
155
  output += f"partitioning: {ut.print_truncated_list(self._partitioning)}\n"
157
156
 
158
- 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"element_metadata({str(len(self._element_metadata))} rows): {ut.print_truncated_list(list(self._element_metadata.get_column_names()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
159
158
  output += f"metadata({str(len(self._metadata))}): {ut.print_truncated_list(list(self._metadata.keys()), sep=' ', include_brackets=False, transform=lambda y: y)}\n"
160
159
 
161
160
  return output
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compressed-lists
3
- Version: 0.4.2
3
+ Version: 0.4.4
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
@@ -14,9 +14,9 @@ Requires-Python: >=3.9
14
14
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
15
  License-File: LICENSE.txt
16
16
  Requires-Dist: importlib-metadata; python_version < "3.8"
17
- Requires-Dist: biocutils>=0.3.1
17
+ Requires-Dist: biocutils>=0.3.3
18
18
  Requires-Dist: numpy
19
- Requires-Dist: biocframe>=0.7.1
19
+ Requires-Dist: biocframe>=0.7.2
20
20
  Provides-Extra: testing
21
21
  Requires-Dist: setuptools; extra == "testing"
22
22
  Requires-Dist: pytest; extra == "testing"
@@ -1,6 +1,6 @@
1
- biocutils>=0.3.1
1
+ biocutils>=0.3.3
2
2
  numpy
3
- biocframe>=0.7.1
3
+ biocframe>=0.7.2
4
4
 
5
5
  [:python_version < "3.8"]
6
6
  importlib-metadata
@@ -4,6 +4,7 @@ import biocutils as ut
4
4
  import pytest
5
5
 
6
6
  from compressed_lists import CompressedList
7
+ from biocframe import BiocFrame
7
8
 
8
9
  __author__ = "Jayaram Kancherla"
9
10
  __copyright__ = "Jayaram Kancherla"
@@ -95,14 +96,13 @@ def test_base_metadata(base_list):
95
96
  base_list.metadata = meta
96
97
  assert base_list.metadata == ut.NamedList.from_dict({"source": "test"})
97
98
 
98
- el_meta = {"info": "details"}
99
+ el_meta = BiocFrame({"score": [1, 2, 3]})
99
100
  cl_el_meta = base_list.set_element_metadata(el_meta, in_place=False)
100
- assert base_list.element_metadata == {}
101
- assert cl_el_meta.element_metadata == {"info": "details"}
101
+ assert len(base_list.element_metadata) == 3
102
+ assert cl_el_meta.element_metadata.get_column("score") == el_meta.get_column("score")
102
103
 
103
- with pytest.warns(UserWarning, match="Setting property 'element_metadata'"):
104
- base_list.element_metadata = el_meta
105
- assert base_list.element_metadata == {"info": "details"}
104
+ with pytest.raises(Exception):
105
+ base_list.element_metadata = {"info": "details"}
106
106
 
107
107
 
108
108
  def test_base_copying(base_list):
@@ -46,7 +46,6 @@ def test_bframe_typed_list_column():
46
46
 
47
47
  def test_split_biocframe(frame_data):
48
48
  frame_data.set_column("groups", [0, 0, 1], in_place=True)
49
- print(frame_data)
50
49
  clist = splitAsCompressedList(frame_data, groups_or_partitions=frame_data.get_column("groups"))
51
50
 
52
51
  assert isinstance(clist, CompressedSplitBiocFrameList)
@@ -1,5 +1,5 @@
1
1
  import pytest
2
- from biocutils.boolean_list import BooleanList
2
+ from biocutils import BooleanList
3
3
 
4
4
  from compressed_lists import CompressedBooleanList
5
5
 
@@ -1,5 +1,5 @@
1
1
  import pytest
2
- from biocutils.float_list import FloatList
2
+ from biocutils import FloatList
3
3
 
4
4
  from compressed_lists import CompressedFloatList
5
5
 
@@ -1,6 +1,6 @@
1
1
  import numpy as np
2
2
  import pytest
3
- from biocutils.integer_list import IntegerList
3
+ from biocutils import IntegerList
4
4
 
5
5
  from compressed_lists import CompressedIntegerList, Partitioning
6
6
 
@@ -1,5 +1,5 @@
1
1
  import pytest
2
- from biocutils.string_list import StringList
2
+ from biocutils import StringList
3
3
 
4
4
  from compressed_lists import CompressedStringList
5
5