py-paramstream 0.0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Benjamin Vallin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: py-paramstream
3
+ Version: 0.0.1
4
+ Summary: Python wrapper for the R package param.stream
5
+ Author-email: Benjamin Vallin <ben.vallin@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Benjamin Vallin
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/benvallin/py-paramstream
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: Programming Language :: Python :: 3.10
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Intended Audience :: Science/Research
34
+ Requires-Python: >=3.9
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: rpy2>=3.5
38
+ Requires-Dist: pandas>=1.5
39
+ Dynamic: license-file
40
+
41
+ # ***paramstream***
42
+
43
+ **A Python wrapper for the R package param.stream**
44
+
45
+
46
+ ---
47
+
48
+
49
+ ## Requirements
50
+
51
+ - Python >= 3.9
52
+ - R >= 4.x
53
+ - R package `param.stream` installed
54
+
55
+ Install R package:
56
+
57
+ ```r
58
+ devtools::install_github("benvallin/param.stream")
59
+
60
+ ```
61
+
62
+ ---
@@ -0,0 +1,22 @@
1
+ # ***paramstream***
2
+
3
+ **A Python wrapper for the R package param.stream**
4
+
5
+
6
+ ---
7
+
8
+
9
+ ## Requirements
10
+
11
+ - Python >= 3.9
12
+ - R >= 4.x
13
+ - R package `param.stream` installed
14
+
15
+ Install R package:
16
+
17
+ ```r
18
+ devtools::install_github("benvallin/param.stream")
19
+
20
+ ```
21
+
22
+ ---
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "py-paramstream"
3
+ version = "0.0.1"
4
+ description = "Python wrapper for the R package param.stream"
5
+ readme = "README.md"
6
+ requires-python = ">=3.9"
7
+ license = { file = "LICENSE" }
8
+ authors = [{ name = "Benjamin Vallin", email = "ben.vallin@gmail.com" }]
9
+
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Programming Language :: Python :: 3.10",
13
+ "Operating System :: OS Independent",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Intended Audience :: Science/Research",
16
+ ]
17
+
18
+ dependencies = [
19
+ "rpy2>=3.5",
20
+ "pandas>=1.5"
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/benvallin/py-paramstream"
25
+
26
+ [build-system]
27
+ requires = ["setuptools>=68", "wheel"]
28
+ build-backend = "setuptools.build_meta"
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
32
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ """
2
+ Python wrapper for the R package `param.stream`.
3
+ """
4
+
5
+ from .core import (
6
+ get_params_log_id_from_dict,
7
+ write_params_log_from_dict,
8
+ get_params_log_table
9
+ )
10
+
11
+ __all__ = [
12
+ 'get_params_log_id_from_dict',
13
+ 'write_params_log_from_dict',
14
+ 'get_params_log_table'
15
+ ]
16
+
17
+ from importlib.metadata import version, PackageNotFoundError
18
+
19
+ try:
20
+
21
+ __version__ = version('paramstream')
22
+
23
+ except PackageNotFoundError:
24
+
25
+ __version__ = 'unknown'
@@ -0,0 +1,120 @@
1
+ # %% Set up ----
2
+
3
+ # Import required libraries
4
+ from typing import Union, TypeAlias
5
+ import pandas as pd
6
+ from rpy2.robjects.packages import importr
7
+ from rpy2.robjects.vectors import StrVector, BoolVector, FloatVector, IntVector, ListVector
8
+ from rpy2.robjects import NULL
9
+ from rpy2.robjects import RObject
10
+ from rpy2.rinterface import NULLType
11
+
12
+ # %% _get_paramstream_r() ----
13
+
14
+ def _get_paramstream_r():
15
+
16
+ try:
17
+
18
+ return importr('param.stream')
19
+
20
+ except Exception as e:
21
+
22
+ raise ImportError(
23
+ "R package 'param.stream' is not installed or R is not available."
24
+ ) from e
25
+
26
+ # %% _py_to_r() ----
27
+
28
+ PyScalar: TypeAlias = Union[str, int, float, bool]
29
+ PyValue: TypeAlias = Union[
30
+ None,
31
+ PyScalar,
32
+ list['PyValue'],
33
+ dict[str, 'PyValue'],
34
+ ]
35
+
36
+ def _py_to_r(obj: PyValue) -> Union[RObject, NULLType]:
37
+
38
+ """Convert a supported Python object into the corresponding rpy2 R object
39
+
40
+ Supported conversions:
41
+ None -> R NULL
42
+ bool -> logical vector (length 1)
43
+ str -> character vector (length 1)
44
+ int -> integer vector (length 1)
45
+ float -> numeric vector (length 1)
46
+ list[str] -> character vector
47
+ list[bool] -> logical vector
48
+ list[int] -> integer vector
49
+ list[float] -> numeric vector
50
+ list[mixed] -> R list (recursive conversion)
51
+ dict -> named R list (recursive conversion)
52
+
53
+ Lists and dictionaries are converted recursively.
54
+
55
+ Parameters
56
+ ----------
57
+ obj : Any
58
+ Python object to convert.
59
+
60
+ Returns
61
+ -------
62
+ rpy2.robjects.RObject or rpy2.robjects.NULL
63
+ Equivalent R representation.
64
+
65
+ Raises
66
+ ------
67
+ TypeError
68
+ If the object type is not supported.
69
+
70
+ """
71
+
72
+ if obj is None:
73
+
74
+ return NULL
75
+
76
+ if isinstance(obj, bool):
77
+
78
+ return BoolVector([obj])
79
+
80
+ if isinstance(obj, str):
81
+
82
+ return StrVector([obj])
83
+
84
+ if isinstance(obj, int):
85
+
86
+ return IntVector([obj])
87
+
88
+ if isinstance(obj, float):
89
+
90
+ return FloatVector([obj])
91
+
92
+ if isinstance(obj, list):
93
+
94
+ if len(obj) == 0:
95
+
96
+ return ListVector({})
97
+
98
+ if all(isinstance(x, str) for x in obj):
99
+
100
+ return StrVector(obj)
101
+
102
+ if all(isinstance(x, bool) for x in obj):
103
+
104
+ return BoolVector(obj)
105
+
106
+ if all(isinstance(x, int) for x in obj):
107
+
108
+ return IntVector(obj)
109
+
110
+ if all(isinstance(x, float) for x in obj):
111
+
112
+ return FloatVector(obj)
113
+
114
+ return ListVector({str(i): _py_to_r(v) for i, v in enumerate(obj)})
115
+
116
+ if isinstance(obj, dict):
117
+
118
+ return ListVector({k: _py_to_r(v) for k, v in obj.items()})
119
+
120
+ raise TypeError(f'Unsupported type: {type(obj)}')
@@ -0,0 +1,147 @@
1
+ # %% Set up ----
2
+
3
+ # Import required libraries
4
+ from typing import Optional
5
+ import pandas as pd
6
+ from rpy2.robjects.conversion import localconverter, rpy2py
7
+ from rpy2.robjects.pandas2ri import converter
8
+ from ._conversion import _get_paramstream_r, _py_to_r
9
+
10
+ # %% get_params_log_id_from_dict() ----
11
+
12
+ def get_params_log_id_from_dict(params_dict: dict, in_dir_path: str) -> str:
13
+
14
+ """Get log ID from parameters dict
15
+
16
+ This function is a Python wrapper around param.stream::get_params_log_id_from_list().
17
+ It converts Python objects to their R equivalents before calling the underlying R function.
18
+
19
+ Parameters
20
+ ----------
21
+ params_dict: dict
22
+ Dictionary mapping parameter names to values. Values must be scalars (str, int, float, bool), lists of homogeneous scalars, or None.
23
+ in_dir_path: str
24
+ Path to the directory containing the params.log file.
25
+
26
+ Returns
27
+ -------
28
+ str
29
+ The log ID matching <params_list> in the params.log file at <in_dir_path>.
30
+
31
+ Raises
32
+ ------
33
+ TypeError
34
+ If <params_dict> contains unsupported value types.
35
+ rpy2.rinterface_lib.embedded.RRuntimeError
36
+ If the underlying R function raises an error.
37
+
38
+ """
39
+
40
+ _paramstream_r = _get_paramstream_r()
41
+
42
+ params_list_r = _py_to_r(params_dict)
43
+ in_dir_path_r = _py_to_r(in_dir_path)
44
+
45
+ output_r = _paramstream_r.get_params_log_id_from_list(
46
+ params_list=params_list_r,
47
+ in_dir_path=in_dir_path_r
48
+ )
49
+
50
+ return output_r[0]
51
+
52
+ # %% write_params_log_from_dict() ----
53
+
54
+ def write_params_log_from_dict(params_dict: dict, out_dir_path: str, params_log_table: bool = True) -> Optional[pd.DataFrame]:
55
+
56
+ """Write parameters log file from parameters dict
57
+
58
+ This function is a Python wrapper around param.stream::write_params_log_from_list().
59
+ It converts Python objects to their R equivalents before calling the underlying R function.
60
+
61
+ Parameters
62
+ ----------
63
+ params_dict: dict
64
+ Dictionary mapping parameter names to values. Values must be scalars (str, int, float, bool), lists of homogeneous scalars, or None.
65
+ out_dir_path: str
66
+ Path to the directory where the params.log file should be written.
67
+ params_log_table: bool, default=True
68
+ If True, return the params log table as a pandas DataFrame.
69
+ If False, no value is returned.
70
+
71
+ Returns
72
+ -------
73
+ pd.DataFrame or None
74
+ The params log table if <params_log_table> is True.
75
+
76
+ Raises
77
+ ------
78
+ TypeError
79
+ If <params_dict> contains unsupported value types.
80
+ rpy2.rinterface_lib.embedded.RRuntimeError
81
+ If the underlying R function raises an error.
82
+
83
+ """
84
+ _paramstream_r = _get_paramstream_r()
85
+
86
+ params_list_r = _py_to_r(params_dict)
87
+ out_dir_path_r = _py_to_r(out_dir_path)
88
+ params_log_table_r = _py_to_r(params_log_table)
89
+
90
+ output_r = _paramstream_r.write_params_log_from_list(
91
+ params_list=params_list_r,
92
+ out_dir_path=out_dir_path_r,
93
+ params_log_table=params_log_table_r
94
+ )
95
+
96
+ if params_log_table is False:
97
+
98
+ return
99
+
100
+ else:
101
+
102
+ with localconverter(converter):
103
+
104
+ return rpy2py(output_r)
105
+
106
+ # %% get_params_log_table() ----
107
+
108
+ def get_params_log_table(log_id: str, in_dir_path: str) -> pd.DataFrame:
109
+
110
+ """Get parameters log table from log ID
111
+
112
+ This function is a Python wrapper around param.stream::get_params_log_table().
113
+ It converts Python objects to their R equivalents before calling the underlying R function.
114
+
115
+ Parameters
116
+ ----------
117
+ log_id: str
118
+ log ID for which the log table should be returned.
119
+ in_dir_path: str
120
+ Path to the directory containing the params.log file.
121
+
122
+ Returns
123
+ -------
124
+ pd.DataFrame
125
+ The params log table matching the input <log_id>.
126
+
127
+ Raises
128
+ ------
129
+ rpy2.rinterface_lib.embedded.RRuntimeError
130
+ If the underlying R function raises an error.
131
+
132
+ """
133
+
134
+ _paramstream_r = _get_paramstream_r()
135
+
136
+ log_id_r = _py_to_r(log_id)
137
+ in_dir_path_r = _py_to_r(in_dir_path)
138
+
139
+ output_r = _paramstream_r.get_params_log_table(
140
+ log_id=log_id_r,
141
+ in_dir_path=in_dir_path_r
142
+ )
143
+
144
+ with localconverter(converter):
145
+
146
+ return rpy2py(output_r)
147
+
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: py-paramstream
3
+ Version: 0.0.1
4
+ Summary: Python wrapper for the R package param.stream
5
+ Author-email: Benjamin Vallin <ben.vallin@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Benjamin Vallin
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/benvallin/py-paramstream
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: Programming Language :: Python :: 3.10
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Intended Audience :: Science/Research
34
+ Requires-Python: >=3.9
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: rpy2>=3.5
38
+ Requires-Dist: pandas>=1.5
39
+ Dynamic: license-file
40
+
41
+ # ***paramstream***
42
+
43
+ **A Python wrapper for the R package param.stream**
44
+
45
+
46
+ ---
47
+
48
+
49
+ ## Requirements
50
+
51
+ - Python >= 3.9
52
+ - R >= 4.x
53
+ - R package `param.stream` installed
54
+
55
+ Install R package:
56
+
57
+ ```r
58
+ devtools::install_github("benvallin/param.stream")
59
+
60
+ ```
61
+
62
+ ---
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/paramstream/__init__.py
5
+ src/paramstream/_conversion.py
6
+ src/paramstream/core.py
7
+ src/py_paramstream.egg-info/PKG-INFO
8
+ src/py_paramstream.egg-info/SOURCES.txt
9
+ src/py_paramstream.egg-info/dependency_links.txt
10
+ src/py_paramstream.egg-info/requires.txt
11
+ src/py_paramstream.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ rpy2>=3.5
2
+ pandas>=1.5