tsbootstrap 0.1.2__tar.gz → 0.1.3__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 (62) hide show
  1. {tsbootstrap-0.1.2/src/tsbootstrap.egg-info → tsbootstrap-0.1.3}/PKG-INFO +16 -13
  2. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/README.md +7 -4
  3. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/pyproject.toml +9 -9
  4. tsbootstrap-0.1.3/src/tsbootstrap/registry/_lookup.py +201 -0
  5. tsbootstrap-0.1.3/src/tsbootstrap/registry/_tags.py +287 -0
  6. tsbootstrap-0.1.3/src/tsbootstrap/registry/tests/test_tags.py +267 -0
  7. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/scenarios/scenarios_bootstrap.py +1 -4
  8. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3/src/tsbootstrap.egg-info}/PKG-INFO +16 -13
  9. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap.egg-info/requires.txt +7 -6
  10. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_bootstrap.py +0 -27
  11. tsbootstrap-0.1.2/src/tsbootstrap/registry/_lookup.py +0 -172
  12. tsbootstrap-0.1.2/src/tsbootstrap/registry/_tags.py +0 -102
  13. tsbootstrap-0.1.2/src/tsbootstrap/registry/tests/test_tags.py +0 -46
  14. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/LICENSE +0 -0
  15. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/setup.cfg +0 -0
  16. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/__init__.py +0 -0
  17. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/base_bootstrap.py +0 -0
  18. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/base_bootstrap_configs.py +0 -0
  19. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/block_bootstrap.py +0 -0
  20. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/block_bootstrap_configs.py +0 -0
  21. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/block_generator.py +0 -0
  22. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/block_length_sampler.py +0 -0
  23. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/block_resampler.py +0 -0
  24. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/bootstrap.py +0 -0
  25. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/markov_sampler.py +0 -0
  26. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/py.typed +0 -0
  27. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/ranklags.py +0 -0
  28. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/registry/__init__.py +0 -0
  29. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/registry/tests/__init__.py +0 -0
  30. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/__init__.py +0 -0
  31. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/scenarios/__init__.py +0 -0
  32. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/scenarios/scenarios.py +0 -0
  33. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/scenarios/scenarios_getter.py +0 -0
  34. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/test_all_bootstraps.py +0 -0
  35. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/test_all_estimators.py +0 -0
  36. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/test_class_register.py +0 -0
  37. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tests/test_switch.py +0 -0
  38. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/time_series_model.py +0 -0
  39. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/time_series_simulator.py +0 -0
  40. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/tsfit.py +0 -0
  41. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/__init__.py +0 -0
  42. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/dependencies.py +0 -0
  43. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/estimator_checks.py +0 -0
  44. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/odds_and_ends.py +0 -0
  45. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/types.py +0 -0
  46. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap/utils/validate.py +0 -0
  47. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap.egg-info/SOURCES.txt +0 -0
  48. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap.egg-info/dependency_links.txt +0 -0
  49. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/src/tsbootstrap.egg-info/top_level.txt +0 -0
  50. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_base_bootstrap_configs.py +0 -0
  51. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_block_bootstrap.py +0 -0
  52. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_block_bootstrap_configs.py +0 -0
  53. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_block_generator.py +0 -0
  54. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_block_length_sampler.py +0 -0
  55. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_block_resampler.py +0 -0
  56. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_markov_sampler.py +0 -0
  57. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_odds_and_ends.py +0 -0
  58. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_ranklags.py +0 -0
  59. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_time_series_model.py +0 -0
  60. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_time_series_simulator.py +0 -0
  61. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_tsfit.py +0 -0
  62. {tsbootstrap-0.1.2 → tsbootstrap-0.1.3}/tests/test_validate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tsbootstrap
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A Python package to generate bootstrapped time series
5
5
  Author-email: Sankalp Gilda <sankalp.gilda@gmail.com>
6
6
  Maintainer-email: Sankalp Gilda <sankalp.gilda@gmail.com>, Franz Kiraly <franz.kiraly@sktime.net>, Benedikt Heidrich <benedikt.heidrich@sktime.net>
@@ -34,25 +34,25 @@ Classifier: Operating System :: Microsoft :: Windows
34
34
  Classifier: Operating System :: Unix
35
35
  Classifier: Programming Language :: Python
36
36
  Classifier: Programming Language :: Python :: 3 :: Only
37
- Classifier: Programming Language :: Python :: 3.8
38
37
  Classifier: Programming Language :: Python :: 3.9
39
38
  Classifier: Programming Language :: Python :: 3.10
40
39
  Classifier: Programming Language :: Python :: 3.11
41
40
  Classifier: Programming Language :: Python :: 3.12
42
- Requires-Python: <3.13,>=3.8
41
+ Requires-Python: <3.13,>=3.9
43
42
  Description-Content-Type: text/markdown
44
43
  License-File: LICENSE
45
44
  Requires-Dist: numpy<1.27,>=1.21
46
- Requires-Dist: scikit-base<=0.9.0,>=0.8.0
47
- Requires-Dist: scikit-learn<=1.5.1,>=0.24
48
- Requires-Dist: scipy<2.0.0,>=1.2
49
- Requires-Dist: packaging
45
+ Requires-Dist: scikit-base<0.11,>=0.10.0
46
+ Requires-Dist: scikit-learn<1.6.0,>=1.5.1
47
+ Requires-Dist: scipy<1.14.0,>=1.13
48
+ Requires-Dist: packaging<24.2,>=24.0
49
+ Requires-Dist: pydantic<3.0,>=2.0
50
50
  Provides-Extra: all-extras
51
- Requires-Dist: arch<=7.0.0,>=5.0.0; extra == "all-extras"
51
+ Requires-Dist: arch<7.1.0,>=7.0.0; extra == "all-extras"
52
52
  Requires-Dist: hmmlearn<0.3.2,>=0.3.0; extra == "all-extras"
53
53
  Requires-Dist: pyclustering<0.11.0,>=0.10.0; extra == "all-extras"
54
54
  Requires-Dist: scikit_learn_extra<0.4.0,>=0.3.0; extra == "all-extras"
55
- Requires-Dist: statsmodels<0.15.0,>=0.12.1; extra == "all-extras"
55
+ Requires-Dist: statsmodels<0.15.0,>=0.14.2; extra == "all-extras"
56
56
  Requires-Dist: dtaidistance; python_version < "3.10" and extra == "all-extras"
57
57
  Provides-Extra: docs
58
58
  Requires-Dist: furo; extra == "docs"
@@ -106,6 +106,8 @@ Requires-Dist: tomlkit; extra == "dev"
106
106
  <img src="https://img.shields.io/badge/Pytest-0A9EDC.svg?stylee&logo=Pytest&logoColor=white" alt="pytest" />
107
107
  <img src="https://img.shields.io/badge/GitHub%20Actions-2088FF.svg?style&logo=GitHub-Actions&logoColor=white" alt="actions" />
108
108
  </p>
109
+ <a href="https://arxiv.org/abs/2404.15227"><img src="https://img.shields.io/static/v1?label=arXiv&message=2404.15227&color=B31B1B&logo=arXiv" alt="preprint">
110
+ </a>
109
111
  <a href="https://pypi.org/project/tsbootstrap/">
110
112
  <img src="https://img.shields.io/pypi/v/tsbootstrap?color=5D6D7E&logo=pypi" alt="pypi-version" />
111
113
  </a>
@@ -165,12 +167,13 @@ X = np.arange(n_samples)
165
167
  n_bootstraps = 3
166
168
  block_length = 3
167
169
  rng = 42
168
- mbb = MovingBlockBootstrap(n_bootstraps=n_bootstraps, rng=rng, block_length=block_length)
170
+ mbb = MovingBlockBootstrap(
171
+ n_bootstraps=n_bootstraps, rng=rng, block_length=block_length
172
+ )
169
173
 
170
174
  # Generate bootstrapped samples
171
175
  return_indices = False
172
- bootstrapped_samples = mbb.bootstrap(
173
- X, return_indices=return_indices)
176
+ bootstrapped_samples = mbb.bootstrap(X, return_indices=return_indices)
174
177
 
175
178
  # Collect bootstrap samples
176
179
  X_bootstrapped = []
@@ -186,7 +189,7 @@ X_bootstrapped = np.array(X_bootstrapped)
186
189
 
187
190
  #### ✔️ Prerequisites
188
191
 
189
- - Python (3.8 or higher)
192
+ - Python (3.9 or higher)
190
193
  - `pip` (latest version recommended), plus suitable environment manager (`venv`, `conda`)
191
194
 
192
195
  You can also consider using ``uv`` to speed up environment setu.
@@ -16,6 +16,8 @@
16
16
  <img src="https://img.shields.io/badge/Pytest-0A9EDC.svg?stylee&logo=Pytest&logoColor=white" alt="pytest" />
17
17
  <img src="https://img.shields.io/badge/GitHub%20Actions-2088FF.svg?style&logo=GitHub-Actions&logoColor=white" alt="actions" />
18
18
  </p>
19
+ <a href="https://arxiv.org/abs/2404.15227"><img src="https://img.shields.io/static/v1?label=arXiv&message=2404.15227&color=B31B1B&logo=arXiv" alt="preprint">
20
+ </a>
19
21
  <a href="https://pypi.org/project/tsbootstrap/">
20
22
  <img src="https://img.shields.io/pypi/v/tsbootstrap?color=5D6D7E&logo=pypi" alt="pypi-version" />
21
23
  </a>
@@ -75,12 +77,13 @@ X = np.arange(n_samples)
75
77
  n_bootstraps = 3
76
78
  block_length = 3
77
79
  rng = 42
78
- mbb = MovingBlockBootstrap(n_bootstraps=n_bootstraps, rng=rng, block_length=block_length)
80
+ mbb = MovingBlockBootstrap(
81
+ n_bootstraps=n_bootstraps, rng=rng, block_length=block_length
82
+ )
79
83
 
80
84
  # Generate bootstrapped samples
81
85
  return_indices = False
82
- bootstrapped_samples = mbb.bootstrap(
83
- X, return_indices=return_indices)
86
+ bootstrapped_samples = mbb.bootstrap(X, return_indices=return_indices)
84
87
 
85
88
  # Collect bootstrap samples
86
89
  X_bootstrapped = []
@@ -96,7 +99,7 @@ X_bootstrapped = np.array(X_bootstrapped)
96
99
 
97
100
  #### ✔️ Prerequisites
98
101
 
99
- - Python (3.8 or higher)
102
+ - Python (3.9 or higher)
100
103
  - `pip` (latest version recommended), plus suitable environment manager (`venv`, `conda`)
101
104
 
102
105
  You can also consider using ``uv`` to speed up environment setu.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tsbootstrap"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "A Python package to generate bootstrapped time series"
5
5
  maintainers = [
6
6
  { name = "Sankalp Gilda", email = "sankalp.gilda@gmail.com" },
@@ -12,7 +12,7 @@ authors = [
12
12
  ]
13
13
  license = { file = "LICENSE" }
14
14
  readme = "README.md"
15
- requires-python = ">=3.8,<3.13"
15
+ requires-python = ">=3.9,<3.13"
16
16
  classifiers = [
17
17
  "Development Status :: 4 - Beta",
18
18
  "Intended Audience :: Science/Research",
@@ -22,7 +22,6 @@ classifiers = [
22
22
  "Operating System :: Unix",
23
23
  "Programming Language :: Python",
24
24
  "Programming Language :: Python :: 3 :: Only",
25
- "Programming Language :: Python :: 3.8",
26
25
  "Programming Language :: Python :: 3.9",
27
26
  "Programming Language :: Python :: 3.10",
28
27
  "Programming Language :: Python :: 3.11",
@@ -31,20 +30,21 @@ classifiers = [
31
30
 
32
31
  dependencies = [
33
32
  "numpy<1.27,>=1.21",
34
- "scikit-base>=0.8.0,<=0.9.0",
35
- "scikit-learn>=0.24,<=1.5.1",
36
- "scipy>=1.2,<2.0.0",
37
- "packaging",
33
+ "scikit-base>=0.10.0,<0.11",
34
+ "scikit-learn>=1.5.1,<1.6.0",
35
+ "scipy>=1.13,<1.14.0",
36
+ "packaging>=24.0,<24.2",
37
+ "pydantic>=2.0,<3.0",
38
38
  ]
39
39
 
40
40
  [project.optional-dependencies]
41
41
 
42
42
  all-extras = [
43
- "arch>=5.0.0,<=7.0.0",
43
+ "arch>=7.0.0,<7.1.0",
44
44
  "hmmlearn>=0.3.0,<0.3.2",
45
45
  "pyclustering>=0.10.0,<0.11.0",
46
46
  "scikit_learn_extra>=0.3.0,<0.4.0",
47
- "statsmodels>=0.12.1,<0.15.0",
47
+ "statsmodels>=0.14.2,<0.15.0",
48
48
  "dtaidistance; python_version < '3.10'",
49
49
  ]
50
50
 
@@ -0,0 +1,201 @@
1
+ """
2
+ Registry lookup methods.
3
+
4
+ This module exports the following methods for registry lookup:
5
+
6
+ - all_objects(object_types: Optional[Union[str, List[str]]] = None,
7
+ filter_tags: Optional[Dict[str, Union[str, List[str], bool]]] = None,
8
+ exclude_objects: Optional[Union[str, List[str]]] = None,
9
+ return_names: bool = True,
10
+ as_dataframe: bool = False,
11
+ return_tags: Optional[Union[str, List[str]]] = None,
12
+ suppress_import_stdout: bool = True) -> Union[List[Any], List[Tuple]]
13
+ Lookup and filtering of objects in the tsbootstrap registry.
14
+ """
15
+
16
+ from pathlib import Path
17
+ from typing import Any, Dict, List, Optional, Tuple, Union
18
+
19
+ from skbase.base import BaseObject
20
+ from skbase.lookup import all_objects as _all_objects
21
+
22
+ from tsbootstrap.registry._tags import (
23
+ OBJECT_TAG_REGISTER,
24
+ check_tag_is_valid,
25
+ )
26
+
27
+ VALID_OBJECT_TYPE_STRINGS: set = {tag.scitype for tag in OBJECT_TAG_REGISTER}
28
+
29
+
30
+ def all_objects(
31
+ object_types: Optional[Union[str, List[str]]] = None,
32
+ filter_tags: Optional[
33
+ Union[str, Dict[str, Union[str, List[str], bool]]]
34
+ ] = None,
35
+ exclude_objects: Optional[Union[str, List[str]]] = None,
36
+ return_names: bool = True,
37
+ as_dataframe: bool = False,
38
+ return_tags: Optional[Union[str, List[str]]] = None,
39
+ suppress_import_stdout: bool = True,
40
+ ) -> Union[List[Any], List[Tuple]]:
41
+ """
42
+ Get a list of all objects from tsbootstrap.
43
+
44
+ This function crawls the module and retrieves all classes that inherit
45
+ from tsbootstrap's and sklearn's base classes.
46
+
47
+ Excluded from retrieval are:
48
+ - The base classes themselves
49
+ - Classes defined in test modules
50
+
51
+ Parameters
52
+ ----------
53
+ object_types : Union[str, List[str]], optional (default=None)
54
+ Specifies which types of objects to return.
55
+ - If None, no filtering is applied and all objects are returned.
56
+ - If str or list of str, only objects matching the specified scitypes are returned.
57
+ Valid scitypes are entries in `registry.BASE_CLASS_REGISTER` (first column).
58
+
59
+ filter_tags : Union[str, Dict[str, Union[str, List[str], bool]]], optional (default=None)
60
+ Dictionary or string to filter returned objects based on their tags.
61
+ - If a string, it is treated as a boolean tag filter with the value `True`.
62
+ - If a dictionary, each key-value pair represents a filter condition in an "AND" conjunction.
63
+ - Key is the tag name to filter on.
64
+ - Value is a string, list of strings, or boolean that the tag value must match or be within.
65
+ - Only objects satisfying all filter conditions are returned.
66
+
67
+ exclude_objects : Union[str, List[str]], optional (default=None)
68
+ Names of objects to exclude from the results.
69
+
70
+ return_names : bool, optional (default=True)
71
+ - If True, the object's class name is included in the returned results.
72
+ - If False, the class name is omitted.
73
+
74
+ as_dataframe : bool, optional (default=False)
75
+ - If True, returns a pandas.DataFrame with named columns for all returned attributes.
76
+ - If False, returns a list (of objects or tuples).
77
+
78
+ return_tags : Union[str, List[str]], optional (default=None)
79
+ - Names of tags to fetch and include in the returned results.
80
+ - If specified, tag values are appended as either columns or tuple entries.
81
+
82
+ suppress_import_stdout : bool, optional (default=True)
83
+ Whether to suppress stdout printout upon import.
84
+
85
+ Returns
86
+ -------
87
+ Union[List[Any], List[Tuple]]
88
+ Depending on the parameters:
89
+ 1. List of objects:
90
+ - Entries are objects matching the query, in alphabetical order of object name.
91
+ 2. List of tuples:
92
+ - Each tuple contains (optional object name, object class, optional object tags).
93
+ - Ordered alphabetically by object name.
94
+ 3. pandas.DataFrame:
95
+ - Columns represent the returned attributes.
96
+ - Includes "objects", "names", and any specified tag columns.
97
+
98
+ Examples
99
+ --------
100
+ >>> from tsbootstrap.registry import all_objects
101
+ >>> # Return a complete list of objects as a DataFrame
102
+ >>> all_objects(as_dataframe=True)
103
+ >>> # Return all bootstrap algorithms by filtering for object type
104
+ >>> all_objects("bootstrap", as_dataframe=True)
105
+ >>> # Return all bootstraps which are block bootstraps
106
+ >>> all_objects(
107
+ ... object_types="bootstrap",
108
+ ... filter_tags={"bootstrap_type": "block"},
109
+ ... as_dataframe=True
110
+ ... )
111
+
112
+ References
113
+ ----------
114
+ Adapted version of sktime's `all_estimators`,
115
+ which is an evolution of scikit-learn's `all_estimators`.
116
+ """
117
+ MODULES_TO_IGNORE = (
118
+ "tests",
119
+ "setup",
120
+ "contrib",
121
+ "utils",
122
+ "all",
123
+ )
124
+
125
+ result: Union[List[Any], List[Tuple]] = []
126
+ ROOT = str(
127
+ Path(__file__).parent.parent
128
+ ) # tsbootstrap package root directory
129
+
130
+ # Prepare filter_tags
131
+ if isinstance(filter_tags, str):
132
+ # Ensure the tag expects a boolean value
133
+ tag = next(
134
+ (t for t in OBJECT_TAG_REGISTER if t.name == filter_tags), None
135
+ )
136
+ if not tag:
137
+ raise ValueError(
138
+ f"Tag '{filter_tags}' not found in OBJECT_TAG_REGISTER."
139
+ )
140
+ if tag.value_type != "bool":
141
+ raise ValueError(
142
+ f"Tag '{filter_tags}' does not expect a boolean value."
143
+ )
144
+ filter_tags = {filter_tags: True}
145
+ elif isinstance(filter_tags, dict):
146
+ # Validate each tag in filter_tags
147
+ for key, value in filter_tags.items():
148
+ try:
149
+ if not check_tag_is_valid(key, value):
150
+ raise ValueError(
151
+ f"Invalid value '{value}' for tag '{key}'."
152
+ )
153
+ except KeyError as e:
154
+ raise ValueError(
155
+ f"Tag '{key}' not found in OBJECT_TAG_REGISTER."
156
+ ) from e
157
+ else:
158
+ filter_tags = None
159
+
160
+ if object_types:
161
+ if isinstance(object_types, str):
162
+ object_types = [object_types]
163
+ # Validate object_types
164
+ invalid_types = set(object_types) - VALID_OBJECT_TYPE_STRINGS
165
+ if invalid_types:
166
+ raise ValueError(
167
+ f"Invalid object_types: {invalid_types}. Valid types are {VALID_OBJECT_TYPE_STRINGS}."
168
+ )
169
+ if filter_tags and "object_type" not in filter_tags:
170
+ object_tag_filter = {"object_type": object_types}
171
+ filter_tags.update(object_tag_filter)
172
+ elif filter_tags and "object_type" in filter_tags:
173
+ existing_filter = filter_tags.get("object_type", [])
174
+ if isinstance(existing_filter, str):
175
+ existing_filter = [existing_filter]
176
+ elif isinstance(existing_filter, list):
177
+ pass
178
+ else:
179
+ raise ValueError(
180
+ f"Unexpected type for 'object_type' filter: {type(existing_filter)}"
181
+ )
182
+ combined_filter = list(set(object_types + existing_filter))
183
+ filter_tags["object_type"] = combined_filter
184
+ else:
185
+ filter_tags = {"object_type": object_types}
186
+
187
+ # Retrieve objects using skbase's all_objects
188
+ result = _all_objects(
189
+ object_types=[BaseObject],
190
+ filter_tags=filter_tags,
191
+ exclude_objects=exclude_objects,
192
+ return_names=return_names,
193
+ as_dataframe=as_dataframe,
194
+ return_tags=return_tags,
195
+ suppress_import_stdout=suppress_import_stdout,
196
+ package_name="tsbootstrap",
197
+ path=ROOT,
198
+ modules_to_ignore=MODULES_TO_IGNORE,
199
+ )
200
+
201
+ return result
@@ -0,0 +1,287 @@
1
+ """
2
+ Register of estimator and object tags.
3
+
4
+ Note for extenders:
5
+ New tags should be entered in `OBJECT_TAG_REGISTER`.
6
+ No other place is necessary to add new tags.
7
+
8
+ This module exports the following:
9
+
10
+ - OBJECT_TAG_REGISTER : List[Tag]
11
+ A list of Tag instances, each representing a tag with its attributes.
12
+
13
+ - OBJECT_TAG_TABLE : List[Dict[str, Any]]
14
+ `OBJECT_TAG_REGISTER` in table form as a list of dictionaries.
15
+
16
+ - OBJECT_TAG_LIST : List[str]
17
+ List of tag names extracted from `OBJECT_TAG_REGISTER`.
18
+
19
+ - check_tag_is_valid(tag_name: str, tag_value: Any) -> bool
20
+ Function to validate if a tag value is valid for a given tag name.
21
+ """
22
+
23
+ from typing import Any, Dict, List, Tuple, Union
24
+
25
+ from pydantic import BaseModel, field_validator
26
+
27
+
28
+ class Tag(BaseModel):
29
+ """
30
+ Represents a single tag with its properties.
31
+
32
+ Attributes
33
+ ----------
34
+ name : str
35
+ Name of the tag as used in the _tags dictionary.
36
+ scitype : str
37
+ Name of the scitype this tag applies to.
38
+ value_type : Union[str, Tuple[str, Union[List[str], str]], List[Union[str, Tuple[str, Union[List[str], str]]]]]
39
+ Expected type(s) of the tag value.
40
+ description : str
41
+ Plain English description of the tag.
42
+ """
43
+
44
+ name: str
45
+ scitype: str
46
+ value_type: Union[
47
+ str,
48
+ Tuple[str, Union[List[str], str]],
49
+ List[Union[str, Tuple[str, Union[List[str], str]]]],
50
+ ]
51
+ description: str
52
+
53
+ @field_validator("value_type")
54
+ @classmethod
55
+ def validate_value_type(cls, v):
56
+ """
57
+ Validates the `value_type` attribute to ensure it adheres to expected formats.
58
+
59
+ Parameters
60
+ ----------
61
+ v : Union[str, Tuple[str, Union[List[str], str]], List[Union[str, Tuple[str, Union[List[str], str]]]]]
62
+ The value to validate.
63
+
64
+ Returns
65
+ -------
66
+ Union[str, Tuple[str, Union[List[str], str]], List[Union[str, Tuple[str, Union[List[str], str]]]]]
67
+ The validated value.
68
+
69
+ Raises
70
+ ------
71
+ ValueError
72
+ If `v` does not conform to expected types and constraints.
73
+ TypeError
74
+ If `v` is neither a string, a tuple, nor a list.
75
+ """
76
+ valid_base_types = {"bool", "int", "str", "list", "dict"}
77
+
78
+ def validate_single_type(single_v):
79
+ if isinstance(single_v, str):
80
+ if single_v not in valid_base_types:
81
+ raise ValueError(
82
+ f"Invalid value_type: {single_v}. Must be one of {valid_base_types}."
83
+ )
84
+ elif isinstance(single_v, tuple):
85
+ if len(single_v) != 2:
86
+ raise ValueError(
87
+ "Tuple value_type must have exactly two elements."
88
+ )
89
+ base, subtype = single_v
90
+ if base not in {"str", "list"}:
91
+ raise ValueError(
92
+ "First element of tuple must be 'str' or 'list'."
93
+ )
94
+ if base == "str":
95
+ if not isinstance(subtype, list) or not all(
96
+ isinstance(item, str) for item in subtype
97
+ ):
98
+ raise ValueError(
99
+ "Second element must be a list of strings when base is 'str'."
100
+ )
101
+ elif base == "list" and not (
102
+ (
103
+ isinstance(subtype, list)
104
+ and all(isinstance(item, str) for item in subtype)
105
+ )
106
+ or isinstance(subtype, str)
107
+ ):
108
+ raise ValueError(
109
+ "Second element must be a list of strings or 'str' when base is 'list'."
110
+ )
111
+ else:
112
+ raise TypeError(
113
+ "Each value_type must be either a string or a tuple."
114
+ )
115
+
116
+ if isinstance(v, list):
117
+ if not v:
118
+ raise ValueError("value_type list cannot be empty.")
119
+ for item in v:
120
+ validate_single_type(item)
121
+ else:
122
+ validate_single_type(v)
123
+
124
+ return v
125
+
126
+
127
+ # Define the OBJECT_TAG_REGISTER with Tag instances
128
+ OBJECT_TAG_REGISTER: List[Tag] = [
129
+ # --------------------------
130
+ # All objects and estimators
131
+ # --------------------------
132
+ Tag(
133
+ name="object_type",
134
+ scitype="object",
135
+ value_type=("str", ["regressor", "transformer"]),
136
+ description="Type of object, e.g., 'regressor', 'transformer'.",
137
+ ),
138
+ Tag(
139
+ name="python_version",
140
+ scitype="object",
141
+ value_type="str",
142
+ description="Python version specifier (PEP 440) for estimator, or None for all versions.",
143
+ ),
144
+ Tag(
145
+ name="python_dependencies",
146
+ scitype="object",
147
+ # Allow both string and list of strings
148
+ value_type=["str", ("list", "str")],
149
+ description="Python dependencies of estimator as string or list of strings.",
150
+ ),
151
+ Tag(
152
+ name="python_dependencies_alias",
153
+ scitype="object",
154
+ value_type="dict",
155
+ description="Alias for Python dependencies if import name differs from package name. Key-value pairs are package name and import name.",
156
+ ),
157
+ # -----------------------
158
+ # BaseTimeSeriesBootstrap
159
+ # -----------------------
160
+ Tag(
161
+ name="bootstrap_type",
162
+ scitype="bootstrap",
163
+ value_type=("list", "str"),
164
+ description="Type(s) of bootstrap the algorithm supports.",
165
+ ),
166
+ Tag(
167
+ name="capability:multivariate",
168
+ scitype="bootstrap",
169
+ value_type="bool",
170
+ description="Whether the bootstrap algorithm supports multivariate data.",
171
+ ),
172
+ # ----------------------------
173
+ # BaseMetaObject reserved tags
174
+ # ----------------------------
175
+ Tag(
176
+ name="named_object_parameters",
177
+ scitype="object",
178
+ value_type="str",
179
+ description="Name of component list attribute for meta-objects.",
180
+ ),
181
+ Tag(
182
+ name="fitted_named_object_parameters",
183
+ scitype="estimator",
184
+ value_type="str",
185
+ description="Name of fitted component list attribute for meta-objects.",
186
+ ),
187
+ ]
188
+
189
+ # Create OBJECT_TAG_TABLE as a list of dictionaries
190
+ OBJECT_TAG_TABLE: List[Dict[str, Any]] = [
191
+ {
192
+ "name": tag.name,
193
+ "scitype": tag.scitype,
194
+ "value_type": tag.value_type,
195
+ "description": tag.description,
196
+ }
197
+ for tag in OBJECT_TAG_REGISTER
198
+ ]
199
+
200
+ # Create OBJECT_TAG_LIST as a list of tag names
201
+ OBJECT_TAG_LIST: List[str] = [tag.name for tag in OBJECT_TAG_REGISTER]
202
+
203
+
204
+ def check_tag_is_valid(tag_name: str, tag_value: Any) -> bool:
205
+ """
206
+ Check whether a tag value is valid for a given tag name.
207
+
208
+ Parameters
209
+ ----------
210
+ tag_name : str
211
+ The name of the tag to validate.
212
+ tag_value : Any
213
+ The value to validate against the tag's expected type.
214
+
215
+ Returns
216
+ -------
217
+ bool
218
+ True if the tag value is valid for the tag name, False otherwise.
219
+
220
+ Raises
221
+ ------
222
+ KeyError
223
+ If the tag_name is not found in OBJECT_TAG_REGISTER.
224
+ """
225
+ try:
226
+ tag = next(tag for tag in OBJECT_TAG_REGISTER if tag.name == tag_name)
227
+ except StopIteration as e:
228
+ raise KeyError(
229
+ f"Tag name '{tag_name}' not found in OBJECT_TAG_REGISTER."
230
+ ) from e
231
+
232
+ value_type = tag.value_type
233
+
234
+ if isinstance(value_type, list):
235
+ # Iterate through each type definition and return True if any matches
236
+ for vt in value_type:
237
+ if isinstance(vt, str):
238
+ if isinstance(tag_value, str):
239
+ return True
240
+ elif isinstance(vt, tuple):
241
+ base_type, subtype = vt
242
+ if base_type == "str":
243
+ if isinstance(tag_value, str) and tag_value in subtype:
244
+ return True
245
+ elif base_type == "list" and isinstance(tag_value, list):
246
+ if subtype == "str":
247
+ if all(isinstance(item, str) for item in tag_value):
248
+ return True
249
+ elif isinstance(subtype, list) and all(
250
+ isinstance(item, str) and item in subtype
251
+ for item in tag_value
252
+ ):
253
+ return True
254
+ return False
255
+ elif isinstance(value_type, str):
256
+ expected_type = value_type
257
+ if expected_type == "bool":
258
+ return isinstance(tag_value, bool)
259
+ elif expected_type == "int":
260
+ return isinstance(tag_value, int)
261
+ elif expected_type == "str":
262
+ return isinstance(tag_value, str)
263
+ elif expected_type == "list":
264
+ return isinstance(tag_value, list)
265
+ elif expected_type == "dict":
266
+ return isinstance(tag_value, dict)
267
+ else:
268
+ return False
269
+ elif isinstance(value_type, tuple):
270
+ base_type, subtype = value_type
271
+ if base_type == "str":
272
+ if isinstance(tag_value, str):
273
+ return tag_value in subtype
274
+ return False
275
+ elif base_type == "list":
276
+ if not isinstance(tag_value, list):
277
+ return False
278
+ if isinstance(subtype, list):
279
+ return all(
280
+ isinstance(item, str) and item in subtype
281
+ for item in tag_value
282
+ )
283
+ elif subtype == "str":
284
+ return all(isinstance(item, str) for item in tag_value)
285
+ return False
286
+ else:
287
+ return False