biocutils 0.3.1.dev0__tar.gz → 0.3.2.dev1__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.
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/PKG-INFO +1 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/__init__.py +0 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/_utils_combine.py +0 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/assign.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/assign_rows.py +3 -3
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/assign_sequence.py +6 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/bioc_object.py +10 -5
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/boolean_list.py +25 -22
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/combine.py +5 -5
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/combine_columns.py +8 -9
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/combine_rows.py +6 -4
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/combine_sequences.py +6 -5
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/convert_to_dense.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/extract_column_names.py +3 -4
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/extract_row_names.py +2 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/factor.py +79 -42
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/float_list.py +15 -10
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/integer_list.py +17 -13
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/is_high_dimensional.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/is_list_of_type.py +4 -7
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/is_missing_scalar.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/map_to_index.py +3 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/match.py +3 -4
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/named_list.py +45 -35
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/names.py +20 -25
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/normalize_subscript.py +15 -5
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/package_utils.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/print_truncated.py +13 -6
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/print_wrapped_table.py +3 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/relaxed_combine_columns.py +5 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/relaxed_combine_rows.py +3 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/reverse_index.py +1 -2
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/show_as_cell.py +1 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/string_list.py +15 -9
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/which.py +0 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/PKG-INFO +1 -1
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/SOURCES.txt +0 -1
- biocutils-0.3.1.dev0/src/biocutils/table.py +0 -38
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.coveragerc +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.github/workflows/publish-pypi.yml +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.github/workflows/run-tests.yml +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.gitignore +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.pre-commit-config.yaml +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/.readthedocs.yml +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/AUTHORS.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/CHANGELOG.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/CONTRIBUTING.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/LICENSE.txt +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/README.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/Makefile +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/_static/.gitignore +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/authors.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/changelog.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/conf.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/contributing.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/index.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/license.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/readme.md +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/docs/requirements.txt +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/pyproject.toml +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/setup.cfg +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/setup.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/factorize.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/get_height.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/intersect.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/subset.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/subset_rows.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/subset_sequence.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils/union.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/dependency_links.txt +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/not-zip-safe +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/requires.txt +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/src/biocutils.egg-info/top_level.txt +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/conftest.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_BooleanList.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_Factor.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_FloatList.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_IntegerList.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_NamedList.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_Names.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_StringList.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_assign.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_assign_rows.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_assign_sequence.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_biocobject.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_combine.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_combine_columns.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_combine_rows.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_combine_sequences.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_extract_column_names.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_extract_row_names.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_factorize.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_get_height.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_intersect.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_is_high_dimensional.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_list_type_checks.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_map_to_index.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_match.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_normalize_subscript.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_package_utils.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_print_truncated.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_print_wrapped_table.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_show_as_cell.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_subset.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_subset_rows.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_subset_sequence.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_union.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tests/test_which.py +0 -0
- {biocutils-0.3.1.dev0 → biocutils-0.3.2.dev1}/tox.ini +0 -0
|
@@ -14,8 +14,7 @@ def assign(x: Any, indices: Sequence[int], replacement: Any) -> Any:
|
|
|
14
14
|
:py:func:`~biocutils.assign_sequence.assign_sequence` instead.
|
|
15
15
|
|
|
16
16
|
Args:
|
|
17
|
-
x:
|
|
18
|
-
Object to be assignted.
|
|
17
|
+
x: Object to be assignted.
|
|
19
18
|
|
|
20
19
|
Returns:
|
|
21
20
|
The object after assignment, typically the same type as ``x``.
|
|
@@ -31,15 +31,15 @@ def assign_rows(x: Any, indices: Sequence[int], replacement: Any) -> Any:
|
|
|
31
31
|
tmp = [slice(None)] * len(x.shape)
|
|
32
32
|
tmp[0] = indices
|
|
33
33
|
output[(*tmp,)] = replacement
|
|
34
|
-
|
|
35
34
|
return output
|
|
36
35
|
|
|
37
36
|
|
|
38
37
|
@assign_rows.register
|
|
39
|
-
def _assign_rows_numpy(
|
|
38
|
+
def _assign_rows_numpy(
|
|
39
|
+
x: numpy.ndarray, indices: Sequence[int], replacement: Any
|
|
40
|
+
) -> numpy.ndarray:
|
|
40
41
|
tmp = [slice(None)] * len(x.shape)
|
|
41
42
|
tmp[0] = indices
|
|
42
43
|
output = numpy.copy(x)
|
|
43
44
|
output[(*tmp,)] = replacement
|
|
44
|
-
|
|
45
45
|
return output
|
|
@@ -41,14 +41,18 @@ def _assign_sequence_list(x: list, indices: Sequence[int], replacement: Any) ->
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
@assign_sequence.register
|
|
44
|
-
def _assign_sequence_numpy(
|
|
44
|
+
def _assign_sequence_numpy(
|
|
45
|
+
x: numpy.ndarray, indices: Sequence[int], replacement: Any
|
|
46
|
+
) -> numpy.ndarray:
|
|
45
47
|
output = numpy.copy(x)
|
|
46
48
|
output[indices] = replacement
|
|
47
49
|
return output
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
@assign_sequence.register
|
|
51
|
-
def _assign_sequence_range(
|
|
53
|
+
def _assign_sequence_range(
|
|
54
|
+
x: range, indices: Sequence[int], replacement: Any
|
|
55
|
+
) -> Union[range, list]:
|
|
52
56
|
if (
|
|
53
57
|
isinstance(replacement, range)
|
|
54
58
|
and isinstance(indices, range)
|
|
@@ -4,6 +4,11 @@ import copy
|
|
|
4
4
|
from typing import Any, Dict, Optional, Union
|
|
5
5
|
from warnings import warn
|
|
6
6
|
|
|
7
|
+
try:
|
|
8
|
+
from typing import Self
|
|
9
|
+
except ImportError:
|
|
10
|
+
Self = "BiocObject"
|
|
11
|
+
|
|
7
12
|
from .named_list import NamedList
|
|
8
13
|
|
|
9
14
|
__author__ = "Jayaram Kancherla"
|
|
@@ -35,22 +40,22 @@ class BiocObject:
|
|
|
35
40
|
Provides a standardized `metadata` slot and copy-on-write semantics.
|
|
36
41
|
"""
|
|
37
42
|
|
|
38
|
-
def __init__(self, metadata: Optional[Union[Dict[str, Any], NamedList]] = None,
|
|
43
|
+
def __init__(self, metadata: Optional[Union[Dict[str, Any], NamedList]] = None, validate: bool = True) -> None:
|
|
39
44
|
"""Initialize the BiocObject.
|
|
40
45
|
|
|
41
46
|
Args:
|
|
42
47
|
metadata:
|
|
43
48
|
Additional metadata. Defaults to an empty NamedList.
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
validate:
|
|
46
51
|
Whether to validate the input. Defaults to True.
|
|
47
52
|
"""
|
|
48
|
-
if
|
|
53
|
+
if validate and metadata is not None:
|
|
49
54
|
_validate_metadata(metadata)
|
|
50
55
|
|
|
51
56
|
self._metadata = sanitize_metadata(metadata)
|
|
52
57
|
|
|
53
|
-
def _define_output(self, in_place: bool = False) ->
|
|
58
|
+
def _define_output(self, in_place: bool = False) -> Self:
|
|
54
59
|
"""Internal utility to handle in-place vs copy-on-modify."""
|
|
55
60
|
if in_place:
|
|
56
61
|
return self
|
|
@@ -88,7 +93,7 @@ class BiocObject:
|
|
|
88
93
|
"""Alias for :py:attr:`~metadata` getter."""
|
|
89
94
|
return self.metadata
|
|
90
95
|
|
|
91
|
-
def set_metadata(self, metadata: Optional[Union[Dict[str, Any], NamedList]], in_place: bool = False) ->
|
|
96
|
+
def set_metadata(self, metadata: Optional[Union[Dict[str, Any], NamedList]], in_place: bool = False) -> Self:
|
|
92
97
|
"""Set new metadata.
|
|
93
98
|
|
|
94
99
|
Args:
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from typing import Any, Iterable, Optional, Sequence, Union
|
|
4
2
|
|
|
5
3
|
from .named_list import NamedList
|
|
@@ -18,8 +16,7 @@ class _SubscriptCoercer:
|
|
|
18
16
|
"""Initialize the coercer.
|
|
19
17
|
|
|
20
18
|
Args:
|
|
21
|
-
data:
|
|
22
|
-
Sequence of values to coerce.
|
|
19
|
+
data: Sequence of values to coerce.
|
|
23
20
|
"""
|
|
24
21
|
self._data = data
|
|
25
22
|
|
|
@@ -27,8 +24,7 @@ class _SubscriptCoercer:
|
|
|
27
24
|
"""Get an item and coerce it to boolean.
|
|
28
25
|
|
|
29
26
|
Args:
|
|
30
|
-
index:
|
|
31
|
-
Index of the item.
|
|
27
|
+
index: Index of the item.
|
|
32
28
|
|
|
33
29
|
Returns:
|
|
34
30
|
Coerced boolean value.
|
|
@@ -46,7 +42,7 @@ class BooleanList(NamedList):
|
|
|
46
42
|
|
|
47
43
|
def __init__(
|
|
48
44
|
self,
|
|
49
|
-
data: Optional[
|
|
45
|
+
data: Optional[Iterable] = None,
|
|
50
46
|
names: Optional[Names] = None,
|
|
51
47
|
_validate: bool = True,
|
|
52
48
|
):
|
|
@@ -64,34 +60,41 @@ class BooleanList(NamedList):
|
|
|
64
60
|
_validate:
|
|
65
61
|
Internal use only.
|
|
66
62
|
"""
|
|
67
|
-
if
|
|
68
|
-
if
|
|
69
|
-
data
|
|
70
|
-
else:
|
|
71
|
-
if isinstance(data, NamedList):
|
|
63
|
+
if _validate:
|
|
64
|
+
if data is not None:
|
|
65
|
+
if isinstance(data, BooleanList):
|
|
72
66
|
data = data._data
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
else:
|
|
68
|
+
if isinstance(data, NamedList):
|
|
69
|
+
data = data._data
|
|
70
|
+
original = data
|
|
71
|
+
data = list(_coerce_to_bool(item) for item in original)
|
|
77
72
|
super().__init__(data, names, _validate=_validate)
|
|
78
73
|
|
|
79
|
-
def set_value(
|
|
74
|
+
def set_value(
|
|
75
|
+
self, index: Union[int, str], value: Any, in_place: bool = False
|
|
76
|
+
) -> "BooleanList":
|
|
80
77
|
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a boolean."""
|
|
81
78
|
return super().set_value(index, _coerce_to_bool(value), in_place=in_place)
|
|
82
79
|
|
|
83
|
-
def set_slice(
|
|
80
|
+
def set_slice(
|
|
81
|
+
self, index: SubscriptTypes, value: Sequence, in_place: bool = False
|
|
82
|
+
) -> "BooleanList":
|
|
84
83
|
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to booleans."""
|
|
85
84
|
return super().set_slice(index, _SubscriptCoercer(value), in_place=in_place)
|
|
86
85
|
|
|
87
|
-
def safe_insert(
|
|
86
|
+
def safe_insert(
|
|
87
|
+
self, index: Union[int, str], value: Any, in_place: bool = False
|
|
88
|
+
) -> "BooleanList":
|
|
88
89
|
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a boolean."""
|
|
89
90
|
return super().safe_insert(index, _coerce_to_bool(value), in_place=in_place)
|
|
90
91
|
|
|
91
|
-
def safe_append(self, value: Any, in_place: bool = False) -> BooleanList:
|
|
92
|
+
def safe_append(self, value: Any, in_place: bool = False) -> "BooleanList":
|
|
92
93
|
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_append` after coercing ``value`` to a boolean."""
|
|
93
94
|
return super().safe_append(_coerce_to_bool(value), in_place=in_place)
|
|
94
95
|
|
|
95
|
-
def safe_extend(self, other: Iterable, in_place: bool =
|
|
96
|
+
def safe_extend(self, other: Iterable, in_place: bool = True) -> "BooleanList":
|
|
96
97
|
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_extend` after coercing elements of ``other`` to booleans."""
|
|
97
|
-
return super().safe_extend(
|
|
98
|
+
return super().safe_extend(
|
|
99
|
+
(_coerce_to_bool(y) for y in other), in_place=in_place
|
|
100
|
+
)
|
|
@@ -5,7 +5,7 @@ from .combine_sequences import combine_sequences
|
|
|
5
5
|
from .is_high_dimensional import is_high_dimensional
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def combine(*x: Any)
|
|
8
|
+
def combine(*x: Any):
|
|
9
9
|
"""
|
|
10
10
|
Generic combine that checks if the objects are n-dimensional for n > 1
|
|
11
11
|
(i.e. has a ``shape`` property of length greater than 1); if so, it calls
|
|
@@ -14,8 +14,7 @@ def combine(*x: Any) -> Any:
|
|
|
14
14
|
:py:func:`~biocutils.combine_sequences.combine_sequences` instead.
|
|
15
15
|
|
|
16
16
|
Args:
|
|
17
|
-
x:
|
|
18
|
-
Objects to combine.
|
|
17
|
+
x: Objects to combine.
|
|
19
18
|
|
|
20
19
|
Returns:
|
|
21
20
|
A combined object, typically the same type as the first element in ``x``.
|
|
@@ -29,8 +28,9 @@ def combine(*x: Any) -> Any:
|
|
|
29
28
|
has_1d = True
|
|
30
29
|
|
|
31
30
|
if has_nd and has_1d:
|
|
32
|
-
raise ValueError(
|
|
33
|
-
|
|
31
|
+
raise ValueError(
|
|
32
|
+
"cannot mix 1-dimensional and higher-dimensional objects in `combine`"
|
|
33
|
+
)
|
|
34
34
|
if has_nd:
|
|
35
35
|
return combine_rows(*x)
|
|
36
36
|
else:
|
|
@@ -19,7 +19,7 @@ __license__ = "MIT"
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
@singledispatch
|
|
22
|
-
def combine_columns(*x: Any)
|
|
22
|
+
def combine_columns(*x: Any):
|
|
23
23
|
"""Combine n-dimensional objects along the second dimension.
|
|
24
24
|
|
|
25
25
|
If all elements are :py:class:`~numpy.ndarray`,
|
|
@@ -40,7 +40,11 @@ def combine_columns(*x: Any) -> Any:
|
|
|
40
40
|
Returns:
|
|
41
41
|
Combined object, typically the same type as the first entry of ``x``
|
|
42
42
|
"""
|
|
43
|
-
raise NotImplementedError(
|
|
43
|
+
raise NotImplementedError(
|
|
44
|
+
"no `combine_columns` method implemented for '"
|
|
45
|
+
+ type(x[0]).__name__
|
|
46
|
+
+ "' objects"
|
|
47
|
+
)
|
|
44
48
|
|
|
45
49
|
|
|
46
50
|
@combine_columns.register
|
|
@@ -53,7 +57,7 @@ def _combine_columns_dense_arrays(*x: numpy.ndarray):
|
|
|
53
57
|
return numpy.concatenate(x, axis=1)
|
|
54
58
|
|
|
55
59
|
|
|
56
|
-
if is_package_installed("scipy"):
|
|
60
|
+
if is_package_installed("scipy") is True:
|
|
57
61
|
import scipy.sparse as sp
|
|
58
62
|
|
|
59
63
|
def _combine_columns_sparse_matrices(*x):
|
|
@@ -81,13 +85,8 @@ if is_package_installed("scipy"):
|
|
|
81
85
|
x = [convert_to_dense(y) for y in x]
|
|
82
86
|
return numpy.concatenate(x, axis=1)
|
|
83
87
|
|
|
84
|
-
try:
|
|
85
|
-
combine_columns.register(sp.sparray, _combine_columns_sparse_arrays)
|
|
86
|
-
except Exception:
|
|
87
|
-
pass
|
|
88
|
-
|
|
89
88
|
|
|
90
|
-
if is_package_installed("pandas"):
|
|
89
|
+
if is_package_installed("pandas") is True:
|
|
91
90
|
from pandas import DataFrame, concat
|
|
92
91
|
|
|
93
92
|
@combine_columns.register(DataFrame)
|
|
@@ -19,7 +19,7 @@ __license__ = "MIT"
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
@singledispatch
|
|
22
|
-
def combine_rows(*x: Any)
|
|
22
|
+
def combine_rows(*x: Any):
|
|
23
23
|
"""Combine n-dimensional objects along their first dimension.
|
|
24
24
|
|
|
25
25
|
If all elements are :py:class:`~numpy.ndarray`, we combine them using
|
|
@@ -40,7 +40,9 @@ def combine_rows(*x: Any) -> Any:
|
|
|
40
40
|
Returns:
|
|
41
41
|
Combined object, typically the same type as the first entry of ``x``.
|
|
42
42
|
"""
|
|
43
|
-
raise NotImplementedError(
|
|
43
|
+
raise NotImplementedError(
|
|
44
|
+
"no `combine_rows` method implemented for '" + type(x[0]).__name__ + "' objects"
|
|
45
|
+
)
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
@combine_rows.register(numpy.ndarray)
|
|
@@ -67,7 +69,7 @@ if is_package_installed("scipy"):
|
|
|
67
69
|
return numpy.concatenate(x)
|
|
68
70
|
|
|
69
71
|
try:
|
|
70
|
-
combine_rows.register(sp.
|
|
72
|
+
combine_rows.register(sp.sparray, _combine_rows_sparse_arrays)
|
|
71
73
|
except Exception:
|
|
72
74
|
pass
|
|
73
75
|
|
|
@@ -82,7 +84,7 @@ if is_package_installed("scipy"):
|
|
|
82
84
|
return numpy.concatenate(x)
|
|
83
85
|
|
|
84
86
|
try:
|
|
85
|
-
combine_rows.register(sp.
|
|
87
|
+
combine_rows.register(sp.spmatrix, _combine_rows_sparse_matrices)
|
|
86
88
|
except Exception:
|
|
87
89
|
pass
|
|
88
90
|
|
|
@@ -13,7 +13,7 @@ __license__ = "MIT"
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@singledispatch
|
|
16
|
-
def combine_sequences(*x: Any)
|
|
16
|
+
def combine_sequences(*x: Any):
|
|
17
17
|
"""Combine vector-like objects (1-dimensional arrays).
|
|
18
18
|
|
|
19
19
|
If all elements are :py:class:`~numpy.ndarray`,
|
|
@@ -34,7 +34,11 @@ def combine_sequences(*x: Any) -> Any:
|
|
|
34
34
|
Returns:
|
|
35
35
|
A combined object, ideally of the same type as the first element in ``x``.
|
|
36
36
|
"""
|
|
37
|
-
raise NotImplementedError(
|
|
37
|
+
raise NotImplementedError(
|
|
38
|
+
"no `combine_sequences` method implemented for '"
|
|
39
|
+
+ type(x[0]).__name__
|
|
40
|
+
+ "' objects"
|
|
41
|
+
)
|
|
38
42
|
|
|
39
43
|
|
|
40
44
|
@combine_sequences.register(list)
|
|
@@ -47,7 +51,6 @@ def _combine_sequences_dense_arrays(*x: numpy.ndarray):
|
|
|
47
51
|
for y in x:
|
|
48
52
|
if numpy.ma.is_masked(y):
|
|
49
53
|
return numpy.ma.concatenate(x, axis=None)
|
|
50
|
-
|
|
51
54
|
return numpy.concatenate(x, axis=None)
|
|
52
55
|
|
|
53
56
|
|
|
@@ -82,7 +85,6 @@ def _combine_sequences_ranges(*x: range):
|
|
|
82
85
|
|
|
83
86
|
if not failed:
|
|
84
87
|
return range(start, stop, step)
|
|
85
|
-
|
|
86
88
|
return list(chain(*x))
|
|
87
89
|
|
|
88
90
|
|
|
@@ -99,5 +101,4 @@ if is_package_installed("pandas") is True:
|
|
|
99
101
|
else:
|
|
100
102
|
elems.append(elem)
|
|
101
103
|
x = elems
|
|
102
|
-
|
|
103
104
|
return concat(x)
|
|
@@ -15,8 +15,7 @@ def convert_to_dense(x: Any) -> numpy.ndarray:
|
|
|
15
15
|
``numpy.concatenate`` doesn't understand.
|
|
16
16
|
|
|
17
17
|
Args:
|
|
18
|
-
x:
|
|
19
|
-
Some array-like object to be stored as a NumPy array.
|
|
18
|
+
x: Some array-like object to be stored as a NumPy array.
|
|
20
19
|
|
|
21
20
|
Returns:
|
|
22
21
|
A NumPy array.
|
|
@@ -11,12 +11,11 @@ __license__ = "MIT"
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@singledispatch
|
|
14
|
-
def extract_column_names(x: Any) ->
|
|
14
|
+
def extract_column_names(x: Any) -> numpy.ndarray:
|
|
15
15
|
"""Access column names from 2-dimensional representations.
|
|
16
16
|
|
|
17
17
|
Args:
|
|
18
|
-
x:
|
|
19
|
-
Any object with column names.
|
|
18
|
+
x: Any object with column names.
|
|
20
19
|
|
|
21
20
|
Returns:
|
|
22
21
|
Array of strings containing column names.
|
|
@@ -28,5 +27,5 @@ if is_package_installed("pandas") is True:
|
|
|
28
27
|
from pandas import DataFrame
|
|
29
28
|
|
|
30
29
|
@extract_column_names.register(DataFrame)
|
|
31
|
-
def _colnames_dataframe(x):
|
|
30
|
+
def _colnames_dataframe(x: DataFrame) -> list:
|
|
32
31
|
return numpy.array(x.columns, dtype=str)
|
|
@@ -11,7 +11,7 @@ __license__ = "MIT"
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@singledispatch
|
|
14
|
-
def extract_row_names(x: Any) ->
|
|
14
|
+
def extract_row_names(x: Any) -> numpy.ndarray:
|
|
15
15
|
"""Access row names from 2-dimensional representations.
|
|
16
16
|
|
|
17
17
|
Args:
|
|
@@ -27,5 +27,5 @@ if is_package_installed("pandas") is True:
|
|
|
27
27
|
from pandas import DataFrame
|
|
28
28
|
|
|
29
29
|
@extract_row_names.register(DataFrame)
|
|
30
|
-
def _rownames_dataframe(x):
|
|
30
|
+
def _rownames_dataframe(x: DataFrame) -> list:
|
|
31
31
|
return numpy.array(x.index, dtype=str)
|