rbartpackages 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 The rbartpackages Contributors
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,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: rbartpackages
3
+ Version: 0.1.0
4
+ Summary: Python wrappers of R BART packages via rpy2
5
+ Author: Giacomo Petrillo
6
+ Author-email: Giacomo Petrillo <info@giacomopetrillo.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Dist: rpy2>=3.6.0
10
+ Requires-Dist: numpy>=2.2.6
11
+ Requires-Dist: jaxtyping>=0.3.2
12
+ Requires-Dist: jax>=0.6.1 ; extra == 'jax'
13
+ Requires-Dist: pandas>=2.2.3 ; extra == 'pandas'
14
+ Requires-Dist: polars>=1.30.0 ; extra == 'polars'
15
+ Requires-Dist: pandas>=2.2.3 ; extra == 'polars'
16
+ Requires-Python: >=3.10
17
+ Project-URL: Homepage, https://github.com/bartz-org/rbartpackages
18
+ Project-URL: Documentation, https://bartz-org.github.io/rbartpackages/docs-dev
19
+ Project-URL: Issues, https://github.com/bartz-org/rbartpackages/issues
20
+ Provides-Extra: jax
21
+ Provides-Extra: pandas
22
+ Provides-Extra: polars
23
+ Description-Content-Type: text/markdown
24
+
25
+ # rbartpackages
26
+
27
+ Python wrappers of R BART (Bayesian Additive Regression Trees) packages, built on [rpy2](https://rpy2.github.io).
28
+
29
+ `rbartpackages` lets you call several R BART implementations from Python with a uniform, lightly-typed interface: arguments are converted to R, the fitted R object's components become Python attributes, and the original R documentation is attached to each wrapper class. It currently wraps:
30
+
31
+ - [`BART`](https://cran.r-project.org/package=BART)
32
+ - [`BART3`](https://github.com/rsparapa/bnptools) (the development superset of `BART`)
33
+ - [`bartMachine`](https://cran.r-project.org/package=bartMachine)
34
+ - [`dbarts`](https://cran.r-project.org/package=dbarts)
35
+
36
+ ## Installation
37
+
38
+ ```sh
39
+ pip install rbartpackages
40
+ ```
41
+
42
+ You also need R with the package(s) you want to use installed (`BART`, `dbarts`, `bartMachine` from CRAN; `BART3` from `rsparapa/bnptools` on GitHub). `bartMachine` additionally requires Java. Optional extras `pandas`, `polars`, and `jax` enable passing those array/frame types directly. See the documentation for details.
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ import numpy as np
48
+ from rbartpackages import BART3
49
+
50
+ x_train = np.random.randn(100, 5)
51
+ y_train = x_train[:, 0] + 0.1 * np.random.randn(100)
52
+
53
+ bart = BART3.gbart(x_train=x_train, y_train=y_train, ndpost=200)
54
+ y_pred = bart.predict(x_train) # shape (ndpost, n)
55
+ ```
56
+
57
+ R argument names with dots are passed with underscores (`x.train` → `x_train`).
58
+
59
+ ## Links
60
+
61
+ - [Documentation](https://bartz-org.github.io/rbartpackages/docs-dev)
62
+ - [Repository](https://github.com/bartz-org/rbartpackages)
63
+ - [List of BART packages](https://bartz-org.github.io/bartz/docs-dev/pkglist.html) (maintained in the bartz docs)
64
+
65
+ These wrappers originated in the [bartz](https://github.com/bartz-org/bartz) project, where they are used to validate against reference R implementations.
@@ -0,0 +1,41 @@
1
+ # rbartpackages
2
+
3
+ Python wrappers of R BART (Bayesian Additive Regression Trees) packages, built on [rpy2](https://rpy2.github.io).
4
+
5
+ `rbartpackages` lets you call several R BART implementations from Python with a uniform, lightly-typed interface: arguments are converted to R, the fitted R object's components become Python attributes, and the original R documentation is attached to each wrapper class. It currently wraps:
6
+
7
+ - [`BART`](https://cran.r-project.org/package=BART)
8
+ - [`BART3`](https://github.com/rsparapa/bnptools) (the development superset of `BART`)
9
+ - [`bartMachine`](https://cran.r-project.org/package=bartMachine)
10
+ - [`dbarts`](https://cran.r-project.org/package=dbarts)
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install rbartpackages
16
+ ```
17
+
18
+ You also need R with the package(s) you want to use installed (`BART`, `dbarts`, `bartMachine` from CRAN; `BART3` from `rsparapa/bnptools` on GitHub). `bartMachine` additionally requires Java. Optional extras `pandas`, `polars`, and `jax` enable passing those array/frame types directly. See the documentation for details.
19
+
20
+ ## Usage
21
+
22
+ ```python
23
+ import numpy as np
24
+ from rbartpackages import BART3
25
+
26
+ x_train = np.random.randn(100, 5)
27
+ y_train = x_train[:, 0] + 0.1 * np.random.randn(100)
28
+
29
+ bart = BART3.gbart(x_train=x_train, y_train=y_train, ndpost=200)
30
+ y_pred = bart.predict(x_train) # shape (ndpost, n)
31
+ ```
32
+
33
+ R argument names with dots are passed with underscores (`x.train` → `x_train`).
34
+
35
+ ## Links
36
+
37
+ - [Documentation](https://bartz-org.github.io/rbartpackages/docs-dev)
38
+ - [Repository](https://github.com/bartz-org/rbartpackages)
39
+ - [List of BART packages](https://bartz-org.github.io/bartz/docs-dev/pkglist.html) (maintained in the bartz docs)
40
+
41
+ These wrappers originated in the [bartz](https://github.com/bartz-org/bartz) project, where they are used to validate against reference R implementations.
@@ -0,0 +1,266 @@
1
+ # rbartpackages/pyproject.toml
2
+ #
3
+ # Copyright (c) 2024-2026, The rbartpackages Contributors
4
+ #
5
+ # This file is part of rbartpackages.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ [build-system]
26
+ requires = ["uv_build>=0.9.5,<0.10.0"]
27
+ build-backend = "uv_build"
28
+
29
+ [project]
30
+ name = "rbartpackages"
31
+ version = "0.1.0"
32
+ description = "Python wrappers of R BART packages via rpy2"
33
+ authors = [{ name = "Giacomo Petrillo", email = "info@giacomopetrillo.com" }]
34
+ license = "MIT"
35
+ license-files = ["LICENSE"]
36
+ readme = "README.md"
37
+ requires-python = ">=3.10"
38
+ dependencies = [
39
+ "rpy2>=3.6.0",
40
+ "numpy>=2.2.6",
41
+ "jaxtyping>=0.3.2",
42
+ ]
43
+
44
+ [project.optional-dependencies]
45
+ # Each extra backs a soft-imported converter in `rbartpackages._base`.
46
+ jax = ["jax>=0.6.1"]
47
+ pandas = ["pandas>=2.2.3"]
48
+ polars = ["polars>=1.30.0", "pandas>=2.2.3"]
49
+
50
+ [project.urls]
51
+ Homepage = "https://github.com/bartz-org/rbartpackages"
52
+ Documentation = "https://bartz-org.github.io/rbartpackages/docs-dev"
53
+ Issues = "https://github.com/bartz-org/rbartpackages/issues"
54
+
55
+ [dependency-groups]
56
+ dev = [
57
+ "ipython>=8.37.0",
58
+ "pre-commit>=4.2.0",
59
+ "rich>=14.0.0",
60
+ "virtualenv>=20.31.2",
61
+ "asv>=0.6.4",
62
+ "gitpython>=3.1.44",
63
+ "packaging>=25.0",
64
+ "pytest>=8.4.0",
65
+ "pytest-cov>=6.1.1",
66
+ # WORKAROUND(pytest<9): pytest 9 has built-in subtests support
67
+ "pytest-subtests>=0.14.1",
68
+ "pytest-timeout>=2.4.0",
69
+ "pytest-xdist>=3.7.0",
70
+ "sphinx>=8.1.3",
71
+ "sphinx-autodoc-typehints>=3.0.1",
72
+ "tomli>=2.2.1",
73
+ "myst-nb>=1.2.0",
74
+ "jupyterlab>=4.4.3",
75
+ "diff-cover>=9.3.2",
76
+ # the soft-imported converters, so they are exercised by the test suite
77
+ "jax>=0.6.1",
78
+ "polars[pandas,pyarrow]>=1.30.0",
79
+ ]
80
+
81
+ # WORKAROUND(pytest<9): use [tool.pytest]
82
+ [tool.pytest.ini_options]
83
+ cache_dir = "config/pytest_cache"
84
+ testpaths = ["tests"]
85
+ addopts = [
86
+ "-r xXfE",
87
+ "--pdbcls=IPython.terminal.debugger:TerminalPdb",
88
+ "--durations=3",
89
+ "--verbose",
90
+ "--import-mode=importlib",
91
+ ]
92
+ filterwarnings = [
93
+ "ignore:unclosed database:ResourceWarning",
94
+ ]
95
+ timeout = 1024 # about 15 min, ci runners are slow
96
+ timeout_method = "thread" # signals do not always work with embedded R
97
+
98
+ [tool.coverage.run]
99
+ branch = true
100
+ source_pkgs = ["rbartpackages", "tests"]
101
+
102
+ [tool.coverage.report]
103
+ show_missing = true
104
+ skip_covered = true
105
+
106
+ [tool.coverage.html]
107
+ show_contexts = true
108
+ directory = "_site/coverage"
109
+
110
+ [tool.coverage.paths]
111
+ # the first path in each list must be the source directory in the machine that's
112
+ # generating the coverage report
113
+
114
+ github = [
115
+ '/home/runner/work/rbartpackages/rbartpackages/src/rbartpackages/',
116
+ '/Users/runner/work/rbartpackages/rbartpackages/src/rbartpackages/',
117
+ 'D:\a\rbartpackages\rbartpackages\src\rbartpackages\',
118
+ '/Library/Frameworks/Python.framework/Versions/*/lib/python*/site-packages/rbartpackages/',
119
+ '/Users/runner/hostedtoolcache/Python/*/*/lib/python*/site-packages/rbartpackages/',
120
+ '/opt/hostedtoolcache/Python/*/*/lib/python*/site-packages/rbartpackages/',
121
+ 'C:\hostedtoolcache\windows\Python\*\*\Lib\site-packages\rbartpackages\',
122
+ ]
123
+
124
+ local = [
125
+ 'src/rbartpackages/',
126
+ '/home/runner/work/rbartpackages/rbartpackages/src/rbartpackages/',
127
+ '/Users/runner/work/rbartpackages/rbartpackages/src/rbartpackages/',
128
+ 'D:\a\rbartpackages\rbartpackages\src\rbartpackages\',
129
+ '/Library/Frameworks/Python.framework/Versions/*/lib/python*/site-packages/rbartpackages/',
130
+ '/Users/runner/hostedtoolcache/Python/*/*/lib/python*/site-packages/rbartpackages/',
131
+ '/opt/hostedtoolcache/Python/*/*/lib/python*/site-packages/rbartpackages/',
132
+ 'C:\hostedtoolcache\windows\Python\*\*\Lib\site-packages\rbartpackages\',
133
+ ]
134
+
135
+ [tool.uv]
136
+ exclude-newer = '1 week'
137
+
138
+ [tool.ruff]
139
+ exclude = [".asv", "*.ipynb"]
140
+ cache-dir = "config/ruff_cache"
141
+
142
+ [tool.ruff.format]
143
+ quote-style = "single"
144
+ skip-magic-trailing-comma = true
145
+
146
+ [tool.ruff.lint.isort]
147
+ split-on-trailing-comma = false
148
+
149
+ [tool.ruff.lint.flake8-annotations]
150
+ allow-star-arg-any = true
151
+
152
+ [tool.ruff.lint]
153
+ select = [
154
+ "ICN", # flake8-import-conventions
155
+ "ERA", # eradicate
156
+ "S", # flake8-bandit
157
+ "BLE", # flake8-blind-except
158
+ "B", # bugbear
159
+ "A", # flake8-builtins
160
+ "C4", # flake8-comprehensions
161
+ "CPY", # flake8-copyright
162
+ "DTZ", # flake8-datetimez
163
+ "T10", # flake8-debugger
164
+ "EM", # flake8-errmsg
165
+ "EXE", # flake8-executable
166
+ "FIX", # flake8-fixme
167
+ "ISC", # flake8-implicit-str-concat
168
+ "INP", # flake8-no-pep420
169
+ "PIE", # flake8-pie
170
+ "T20", # flake8-print
171
+ "PT", # flake8-pytest-style
172
+ "RSE", # flake8-raise
173
+ "RET", # flake8-return
174
+ "SLF", # flake8-self
175
+ "SIM", # flake8-simplify
176
+ "TID", # flake8-tidy-imports
177
+ "ARG", # flake8-unused-arguments
178
+ "PTH", # flake8-use-pathlib
179
+ "FLY", # flynt
180
+ "I", # isort
181
+ "C90", # mccabe
182
+ "NPY", # NumPy-specific rules
183
+ "PERF", # Perflint
184
+ "W", # pycodestyle Warning
185
+ "F", # pyflakes
186
+ "D", # pydocstyle
187
+ "PGH", # pygrep-hooks
188
+ "PLC", # Pylint Convention
189
+ "PLE", # Pylint Error
190
+ "PLR", # Pylint Refactor
191
+ "PLW", # Pyling Warning
192
+ "UP", # pyupgrade
193
+ "FURB", # refurb
194
+ "RUF", # Ruff-specific rules
195
+ "TRY", # tryceratops
196
+ "ANN", # flake8-annotations
197
+ ]
198
+ ignore = [
199
+ "B028", # warn with stacklevel = 2
200
+ "C408", # Unnecessary `dict()` call (rewrite as a literal), it's too convenient for kwargs
201
+ "D105", # Missing docstring in magic method
202
+ "F722", # Syntax error in forward annotation. I ignore this because jaxtyping uses strings for shapes instead of for deferred annotations.
203
+ "PIE790", # Unnecessary ... or pass. Ignored because sometimes I use ... as sentinel to tell the rest of ruff and pyright that an implementation is a stub.
204
+ "PLR0912", # Too many branches; ignore bc C901 already handles this
205
+ "PLR0913", # Too many arguments in function definition. Maybe I should do something about this?
206
+ "PLR2004", # Magic value used in comparison, consider replacing `*` with a constant variable
207
+ "RET505", # Unnecessary `{branch}` after `return` statement. I ignore this because I like to keep branches for readability.
208
+ "RET506", # Unnecessary `else` after `raise` statement. I ignore this because I like to keep branches for readability.
209
+ "S101", # Use of `assert` detected. Too annoying.
210
+ "SIM108", # SIM108 Use ternary operator `*` instead of `if`-`else`-block, I find blocks more readable
211
+ "UP037", # Remove quotes from type annotation. Ignore because jaxtyping.
212
+ ]
213
+
214
+ [tool.ruff.lint.per-file-ignores]
215
+ "{config/*,docs/*}" = [
216
+ "D100", # Missing docstring in public module
217
+ "D101", # Missing docstring in public class
218
+ "D102", # Missing docstring in public method
219
+ "D103", # Missing docstring in public function
220
+ "D104", # Missing docstring in public package
221
+ "INP001", # File * is part of an implicit namespace package. Add an `__init__.py`.
222
+ ]
223
+ "src/rbartpackages/_version.py" = [
224
+ "CPY001", # Missing copyright notice at top of file
225
+ ]
226
+ "{config/*,docs/*,tests/*,benchmarks/*}" = [
227
+ "T201", # `print` found
228
+ ]
229
+ "{tests/*,benchmarks/*}" = [
230
+ "SLF001", # Private member accessed: `*`
231
+ "TID253", # `{module}` is banned at the module level
232
+ ]
233
+
234
+ [tool.ruff.lint.pydocstyle]
235
+ convention = "numpy"
236
+
237
+ [tool.ruff.lint.flake8-copyright]
238
+ min-file-size = 1
239
+
240
+ [tool.ruff.lint.flake8-tidy-imports]
241
+ ban-relative-imports = "all"
242
+
243
+ [tool.ruff.lint.flake8-tidy-imports.banned-api]
244
+ "numpy.testing.assert_allclose".msg = "Use tests.util.assert_allclose (zero default tolerances)."
245
+ "numpy.testing.assert_array_equal".msg = "Use tests.util.assert_array_equal (strict=True default)."
246
+
247
+ [tool.pydoclint]
248
+ arg-type-hints-in-signature = true
249
+ arg-type-hints-in-docstring = false
250
+ check-return-types = false
251
+ check-yield-types = false
252
+ treat-property-methods-as-class-attributes = true
253
+ check-style-mismatch = true
254
+ show-filenames-in-every-violation-message = true
255
+ allow-init-docstring = false
256
+ check-class-attributes = false
257
+ # do not check class attributes because pydoclint only supports them being
258
+ # documented in the class docstring while we document them individually
259
+
260
+ [tool.pydocstringformatter]
261
+ # numpydoc-only style: this leaves out the pep257 `split-summary-body`
262
+ # formatter, which mis-splits our wrapped attribute docstrings at the first
263
+ # physical line (and then inserts mid-sentence periods via `final-period`).
264
+ style = ["numpydoc"]
265
+ # keep the closing `"""` inline on attribute docstrings, as is our convention.
266
+ closing-quotes = false