pyfsda 0.4.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,86 @@
1
+ name: build & publish
2
+
3
+ # Two kinds of runner, for a reason:
4
+ #
5
+ # * build (GitHub-hosted): always builds + metadata-checks the distribution and runs the
6
+ # marshalling UNIT tests best-effort (they need only the `matlabengine` client, which may or
7
+ # may not install on a bare runner -- if it cannot, those tests skip themselves).
8
+ #
9
+ # * integration (SELF-HOSTED): the matlab.engine tests drive real MATLAB via the MATLAB Engine
10
+ # API for Python. MathWorks batch licensing -- the only licensing available on GitHub-hosted
11
+ # runners, with or without an MLM_LICENSE_TOKEN -- does NOT license external language
12
+ # interfaces (Engine API for Python/Java/.NET/C/C++/Fortran). So these tests can ONLY run on a
13
+ # self-hosted runner whose MATLAB is licensed WITHOUT a batch token. See CONTRIBUTING.md.
14
+ #
15
+ # Publishing uses PyPI trusted publishing (OIDC) on a v* tag -- no API token. One-time setup:
16
+ # register this repo + workflow as a Trusted Publisher for `pyfsda` on PyPI.
17
+
18
+ on:
19
+ push:
20
+ branches: [main, master]
21
+ tags: ["v*"]
22
+ pull_request:
23
+ workflow_dispatch:
24
+
25
+ defaults:
26
+ run:
27
+ working-directory: packages/pyfsda
28
+
29
+ jobs:
30
+ build:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - uses: actions/setup-python@v5
35
+ with:
36
+ python-version: "3.12"
37
+ - name: Build sdist + wheel and check metadata
38
+ run: |
39
+ python -m pip install --upgrade pip build twine
40
+ python -m build
41
+ twine check dist/*
42
+ - name: Unit tests (best-effort; needs the matlabengine client)
43
+ run: |
44
+ pip install --no-deps dist/*.whl
45
+ pip install numpy pytest
46
+ pip install matlabengine || echo "matlabengine unavailable on runner -> marshalling tests will skip"
47
+ pytest -m "not integration" -q
48
+ - uses: actions/upload-artifact@v4
49
+ with:
50
+ name: dist
51
+ path: packages/pyfsda/dist/*
52
+
53
+ integration:
54
+ # SECURITY: a self-hosted runner executes the job on YOUR machine. Run it on push / manual
55
+ # dispatch ONLY -- never on `pull_request`, or an untrusted fork PR would run arbitrary code
56
+ # on the runner. Do not remove this guard.
57
+ if: github.event_name != 'pull_request'
58
+ runs-on: [self-hosted, macOS, pyfsda-matlab]
59
+ env:
60
+ # Optional: set repo variable PYFSDA_FSDA_ROOT if FSDA is not on the runner's default
61
+ # MATLAB path. Empty -> the test relies on the machine's default path.
62
+ PYFSDA_FSDA_ROOT: ${{ vars.PYFSDA_FSDA_ROOT }}
63
+ steps:
64
+ - uses: actions/checkout@v4
65
+ - name: Full test suite on the licensed MATLAB machine
66
+ run: |
67
+ rm -rf .ci-venv
68
+ python3 -m venv --system-site-packages .ci-venv # inherit the machine's matlabengine
69
+ ./.ci-venv/bin/python -m pip install --upgrade pip
70
+ ./.ci-venv/bin/pip install --no-deps . # install pyfsda; numpy/matlabengine from system
71
+ ./.ci-venv/bin/pip install numpy pytest
72
+ ./.ci-venv/bin/pytest -q # unit + integration (this machine has MATLAB)
73
+
74
+ publish:
75
+ needs: build # a release never waits on the self-hosted integration job
76
+ if: startsWith(github.ref, 'refs/tags/v')
77
+ runs-on: ubuntu-latest
78
+ environment: pypi
79
+ permissions:
80
+ id-token: write # OIDC token for PyPI trusted publishing
81
+ steps:
82
+ - uses: actions/download-artifact@v4
83
+ with:
84
+ name: dist
85
+ path: dist
86
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,17 @@
1
+ # Build artifacts
2
+ /dist/
3
+ /build/
4
+ *.egg-info/
5
+ .eggs/
6
+
7
+ # Caches
8
+ __pycache__/
9
+ *.py[cod]
10
+ .pytest_cache/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+
14
+ # Virtual environments
15
+ .venv/
16
+ venv/
17
+ .ci-venv/
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+ All notable changes to `pyfsda` are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.4.0] — unreleased
8
+
9
+ ### Added
10
+ - **Optional pandas view at the Python boundary** (`pip install pyfsda[pandas]`, spec 019). pandas stays
11
+ optional and lazily imported — `import pyfsda` works without it, and the neutral
12
+ `dict {VariableNames, RowNames/RowTimes, data, height}` remains the default and the cross-language
13
+ contract (R and Julia surfaces are untouched).
14
+ - **Output:** `frames=True` returns `table`/`timetable` outputs as a `pandas.DataFrame`
15
+ (`pyfsda.<name>(..., frames=True)`); new public helper `pyfsda.to_dataframe(table_dict)` and
16
+ predicate `pyfsda.is_table_dict(obj)`.
17
+ - **Input:** a `pandas.DataFrame` argument is marshalled to a MATLAB `table` (`array2table`, names and
18
+ non-default index preserved). v1 supports numeric/logical columns; other column types raise
19
+ `NotImplementedError`.
20
+
21
+ ## [0.3.0] — unreleased
22
+
23
+ ### Added
24
+ - On the **first `pyfsda.<name>(...)` call**, print (once, best-effort) the **latest FSDA release
25
+ available on GitHub** so you can check your install is current — a stdlib-only query of the FSDA
26
+ releases API, silent on any failure (offline / rate-limited), and gated by `check_version` (disable
27
+ with `pyfsda.start(check_version=False)`). This is separate from, and runs alongside, the existing
28
+ MATLAB-side `tuna` check at engine start.
29
+
30
+ ## [0.2.0] — unreleased
31
+
32
+ ### Added
33
+ - **Functional façade:** call any FSDA routine as a top-level function, e.g.
34
+ `pyfsda.Score(y, X, la=..., intercept=True)` or `pyfsda.mahalFS(Y, MU, SIGMA)` — the shared MATLAB
35
+ session starts lazily on first use and is reused. Backed by a module-level `__getattr__`, so it
36
+ covers every FSDA routine with no per-function code; `from pyfsda import Score` works too.
37
+ - Session helpers `pyfsda.start(...)`, `pyfsda.stop()`, `pyfsda.engine()`; the engine is also stopped
38
+ at interpreter exit. Unknown routine names raise a clear `AttributeError` (typo guard).
39
+
40
+ ## [0.1.0] — unreleased
41
+
42
+ ### Added
43
+ - First packaged release of the generic FSDA ↔ Python bridge (`FsdaEngine`, `to_matlab`,
44
+ `from_matlab`), extracted from the `fsda_python_porting_test` prototype.
45
+ - Routine-agnostic `call` / `eval` surface with generic marshalling
46
+ (numeric ↔ ndarray, struct ↔ dict, cell ↔ list, char ↔ str, table/timetable → dict,
47
+ 2-D cell → nested list) via a MATLAB-workspace round-trip.
48
+ - Best-effort FSDA up-to-date check at `start()` (FSDA `tuna`, quiet unless outdated;
49
+ disable with `check_version=False`).
50
+
51
+ ### Publishing note
52
+ Releases are published to PyPI via GitHub Actions **trusted publishing** (OIDC) on a `v*` tag.
53
+ One-time setup: register `pyfsda` as a Trusted Publisher on PyPI
54
+ (project → *Publishing* → add the GitHub repo + `publish.yml` workflow).
@@ -0,0 +1,95 @@
1
+ # Contributing to pyfsda
2
+
3
+ ## Test layers
4
+
5
+ | Layer | Marker | Needs MATLAB? | Where it runs |
6
+ |---|---|---|---|
7
+ | Marshalling unit tests (`tests/test_marshalling.py`) | *(none)* | No — only the `matlabengine` client (for `matlab.double`) | GitHub-hosted `build` job + locally |
8
+ | Integration smoke (`tests/test_integration.py`) | `integration` | **Yes** — starts MATLAB via `matlab.engine` and calls FSDA | **Self-hosted runner only** + locally |
9
+
10
+ Run locally:
11
+
12
+ ```bash
13
+ pytest -m "not integration" # unit tests
14
+ pytest -m integration # integration (needs MATLAB + FSDA)
15
+ pytest # everything
16
+ ```
17
+
18
+ ## Why the integration tests need a self-hosted runner
19
+
20
+ `pyfsda` drives MATLAB through the **MATLAB Engine API for Python**. MathWorks' hosted-runner
21
+ licensing (`matlab-actions/setup-matlab`) uses **batch licensing**, which — per MathWorks —
22
+ *does not support external language interfaces, including the MATLAB Engine APIs for Python, Java,
23
+ .NET, COM, C, C++, and Fortran*. An `MLM_LICENSE_TOKEN` does **not** lift this: batch licensing simply
24
+ cannot license the Engine API. The only supported path is a **self-hosted runner whose MATLAB is
25
+ licensed without a batch token** (a normal individual/network license). Do not spend time trying to
26
+ make the `matlab.engine` tests run on GitHub-hosted runners — it is not possible.
27
+
28
+ ## Registering a self-hosted runner (one time)
29
+
30
+ On a machine that has a **normally-licensed MATLAB**, FSDA, a matching `matlabengine`, and Python:
31
+
32
+ 1. GitHub → repo **Settings → Actions → Runners → New self-hosted runner**; follow the install steps.
33
+ 2. Apply the labels the `integration` job targets: **`self-hosted`, `macOS`, `pyfsda-matlab`**
34
+ (adjust `macOS` if your runner is Linux/Windows, and update `runs-on` in
35
+ `.github/workflows/publish.yml` to match).
36
+ 3. Run the runner **as the user who holds the MATLAB license** (so `matlab.engine` can start MATLAB
37
+ non-interactively).
38
+
39
+ ### Runner prerequisites
40
+ - **MATLAB** licensed **without** a batch token (individual or network license).
41
+ - **FSDA** on that MATLAB's path (verify `which mahalFS` in MATLAB). If it is *not* on the default
42
+ path, set a repository variable **`PYFSDA_FSDA_ROOT`** to the FSDA install/checkout dir — the job
43
+ forwards it to `FsdaEngine.start(fsda_root=...)`.
44
+ - A **`python3` on `PATH`** whose `matlabengine` matches the MATLAB release
45
+ (e.g. `matlabengine==26.1.*` for R2026a). The job builds a `--system-site-packages` venv so it
46
+ inherits that `matlabengine`.
47
+
48
+ ## Security
49
+
50
+ A self-hosted runner executes workflow code **on your machine**. The `integration` job is therefore
51
+ gated `if: github.event_name != 'pull_request'` and runs only on `push` / `workflow_dispatch`. **Never**
52
+ enable it for `pull_request` events on a public repository — a fork's PR could run arbitrary code on
53
+ your runner. Keep the guard in place.
54
+
55
+ ## Releasing to PyPI (manual, with twine)
56
+
57
+ Publishing is **irreversible**: a given version/filename can never be re-uploaded and the name is
58
+ claimed permanently. Always validate on **TestPyPI** first.
59
+
60
+ ### One-time: accounts + tokens
61
+ 1. Create accounts on <https://test.pypi.org> and <https://pypi.org> and generate an **API token** on
62
+ each (Account settings → API tokens).
63
+ 2. Store them in `~/.pypirc` (chmod 600), never in the repo:
64
+
65
+ ```ini
66
+ [distutils]
67
+ index-servers =
68
+ pypi
69
+ testpypi
70
+
71
+ [pypi]
72
+ username = __token__
73
+ password = pypi-XXXXXXXX # your real-PyPI token
74
+
75
+ [testpypi]
76
+ username = __token__
77
+ password = pypi-YYYYYYYY # your TestPyPI token
78
+ ```
79
+
80
+ ### Each release
81
+ ```bash
82
+ cd packages/pyfsda
83
+ rm -rf dist
84
+ python -m build # fresh sdist + wheel into dist/
85
+ twine check dist/* # metadata + README render must PASS
86
+
87
+ # 1) DRY-RUN on TestPyPI, then eyeball https://test.pypi.org/project/pyfsda/
88
+ twine upload -r testpypi dist/*
89
+
90
+ # 2) only once TestPyPI looks right: publish to real PyPI
91
+ twine upload dist/*
92
+ ```
93
+
94
+ A version can only be uploaded **once** to each index (TestPyPI included) — if you need to re-test after
95
+ a fix, bump the version (e.g. `0.1.1`) in `src/pyfsda/__init__.py` and rebuild.
pyfsda-0.4.0/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
2
+ EUPL © the European Union 2007, 2016
3
+
4
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
5
+ terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
6
+ use is covered by a right of the copyright holder of the Work).
7
+ The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
8
+ notice immediately following the copyright notice for the Work:
9
+ Licensed under the EUPL
10
+ or has expressed by any other means his willingness to license under the EUPL.
11
+
12
+ 1.Definitions
13
+ In this Licence, the following terms have the following meaning:
14
+ — ‘The Licence’:this Licence.
15
+ — ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
16
+ as Source Code and also as Executable Code as the case may be.
17
+ — ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
18
+ modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
19
+ required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
20
+ the country mentioned in Article 15.
21
+ — ‘The Work’:the Original Work or its Derivative Works.
22
+ — ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
23
+ modify.
24
+ — ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
25
+ a computer as a program.
26
+ — ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
27
+ — ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
28
+ the creation of a Derivative Work.
29
+ — ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
30
+ Licence.
31
+ — ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
32
+ transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
33
+ functionalities at the disposal of any other natural or legal person.
34
+
35
+ 2.Scope of the rights granted by the Licence
36
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
37
+ the duration of copyright vested in the Original Work:
38
+ — use the Work in any circumstance and for all usage,
39
+ — reproduce the Work,
40
+ — modify the Work, and make Derivative Works based upon the Work,
41
+ — communicate to the public, including the right to make available or display the Work or copies thereof to the public
42
+ and perform publicly, as the case may be, the Work,
43
+ — distribute the Work or copies thereof,
44
+ — lend and rent the Work or copies thereof,
45
+ — sublicense rights in the Work or copies thereof.
46
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
47
+ applicable law permits so.
48
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
49
+ by law in order to make effective the licence of the economic rights here above listed.
50
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
51
+ extent necessary to make use of the rights granted on the Work under this Licence.
52
+
53
+ 3.Communication of the Source Code
54
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
55
+ Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
56
+ each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
57
+ the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
58
+ distribute or communicate the Work.
59
+
60
+ 4.Limitations on copyright
61
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
62
+ exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
63
+ thereto.
64
+
65
+ 5.Obligations of the Licensee
66
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
67
+ obligations are the following:
68
+
69
+ Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
70
+ the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
71
+ Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
72
+ to carry prominent notices stating that the Work has been modified and the date of modification.
73
+
74
+ Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
75
+ Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
76
+ the Original Work is expressly distributed only under this version of the Licence — for example by communicating
77
+ ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
78
+ Work or Derivative Work that alter or restrict the terms of the Licence.
79
+
80
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
81
+ the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
82
+ under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
83
+ in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
84
+ his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
85
+
86
+ Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
87
+ a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
88
+ for as long as the Licensee continues to distribute or communicate the Work.
89
+ Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
90
+ of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
91
+ reproducing the content of the copyright notice.
92
+
93
+ 6.Chain of Authorship
94
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
95
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
96
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
97
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
98
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
99
+ to the Work, under the terms of this Licence.
100
+
101
+ 7.Disclaimer of Warranty
102
+ The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
103
+ and may therefore contain defects or ‘bugs’ inherent to this type of development.
104
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
105
+ concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
106
+ errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
107
+ Licence.
108
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
109
+
110
+ 8.Disclaimer of Liability
111
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
112
+ liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
113
+ Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
114
+ of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
115
+ the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
116
+
117
+ 9.Additional agreements
118
+ While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
119
+ consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
120
+ responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
121
+ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
122
+ the fact You have accepted any warranty or additional liability.
123
+
124
+ 10.Acceptance of the Licence
125
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
126
+ displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
127
+ applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
128
+ and conditions.
129
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
130
+ by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
131
+ or Communication by You of the Work or copies thereof.
132
+
133
+ 11.Information to the public
134
+ In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
135
+ by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
136
+ must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
137
+ and the way it may be accessible, concluded, stored and reproduced by the Licensee.
138
+
139
+ 12.Termination of the Licence
140
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
141
+ of the Licence.
142
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
143
+ the Licence, provided such persons remain in full compliance with the Licence.
144
+
145
+ 13.Miscellaneous
146
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
147
+ Work.
148
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
149
+ enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
150
+ and enforceable.
151
+ The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
152
+ the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
153
+ New versions of the Licence will be published with a unique version number.
154
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
155
+ advantage of the linguistic version of their choice.
156
+
157
+ 14.Jurisdiction
158
+ Without prejudice to specific agreement between parties,
159
+ — any litigation resulting from the interpretation of this License, arising between the European Union institutions,
160
+ bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
161
+ of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
162
+ — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
163
+ the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
164
+
165
+ 15.Applicable Law
166
+ Without prejudice to specific agreement between parties,
167
+ — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
168
+ resides or has his registered office,
169
+ — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
170
+ a European Union Member State.
171
+
172
+
173
+ Appendix
174
+
175
+ ‘Compatible Licences’ according to Article 5 EUPL are:
176
+ — GNU General Public License (GPL) v. 2, v. 3
177
+ — GNU Affero General Public License (AGPL) v. 3
178
+ — Open Software License (OSL) v. 2.1, v. 3.0
179
+ — Eclipse Public License (EPL) v. 1.0
180
+ — CeCILL v. 2.0, v. 2.1
181
+ — Mozilla Public Licence (MPL) v. 2
182
+ — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
183
+ — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
184
+ — European Union Public Licence (EUPL) v. 1.1, v. 1.2
185
+ — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
186
+
187
+ The European Commission may update this Appendix to later versions of the above licences without producing
188
+ a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
189
+ covered Source Code from exclusive appropriation.
190
+ All other changes or additions to this Appendix require the production of a new EUPL version.
pyfsda-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfsda
3
+ Version: 0.4.0
4
+ Summary: Call FSDA (MATLAB robust-statistics toolbox) routines from Python via the MATLAB Engine.
5
+ Project-URL: Homepage, https://github.com/UniprJRC/FSDA-bridge
6
+ Project-URL: Repository, https://github.com/UniprJRC/FSDA-bridge
7
+ Project-URL: Issues, https://github.com/UniprJRC/FSDA-bridge/issues
8
+ Project-URL: FSDA toolbox, https://github.com/UniprJRC/FSDA
9
+ Author: FSDA team
10
+ Author-email: Aldo Corbellini <aldo.corbellini@gmail.com>
11
+ Maintainer-email: Aldo Corbellini <aldo.corbellini@gmail.com>
12
+ License-Expression: EUPL-1.2
13
+ License-File: LICENSE
14
+ Keywords: forward search,fsda,matlab,matlab engine,outlier detection,robust statistics
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Scientific/Engineering
25
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.9
28
+ Requires-Dist: matlabengine
29
+ Requires-Dist: numpy>=1.22
30
+ Provides-Extra: dev
31
+ Requires-Dist: build; extra == 'dev'
32
+ Requires-Dist: pandas>=1.5; extra == 'dev'
33
+ Requires-Dist: pytest>=7; extra == 'dev'
34
+ Requires-Dist: twine; extra == 'dev'
35
+ Provides-Extra: pandas
36
+ Requires-Dist: pandas>=1.5; extra == 'pandas'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # pyfsda
40
+
41
+ Call [**FSDA**](https://github.com/UniprJRC/FSDA) — the MATLAB *Flexible Statistics and Data
42
+ Analysis* toolbox for robust statistics — from **Python**, using the MATLAB Engine as the
43
+ computational backend. FSDA runs unmodified in MATLAB; `pyfsda` is a thin, routine-agnostic bridge
44
+ that marshals data across the boundary.
45
+
46
+ Call any FSDA routine as a plain Python function — the MATLAB session starts on first use and is
47
+ reused:
48
+
49
+ ```python
50
+ import pyfsda
51
+
52
+ d = pyfsda.mahalFS(Y, MU, SIGMA) # numeric array -> numpy ndarray
53
+ out = pyfsda.Score(y, X, la=la, intercept=True) # struct -> dict (MATLAB-style options)
54
+ RAW, REW = pyfsda.mcd(Y, nargout=2) # two outputs -> tuple
55
+ pyfsda.stop() # optional; also runs automatically at exit
56
+ ```
57
+
58
+ `pyfsda.<name>` works for **any** FSDA function (`from pyfsda import Score` works too). Prefer managing
59
+ the session yourself? Use the explicit engine:
60
+
61
+ ```python
62
+ from pyfsda import FsdaEngine
63
+
64
+ eng = FsdaEngine.start("mahalFS")
65
+ d = eng.call("mahalFS", Y, MU, SIGMA)
66
+ eng.stop()
67
+ ```
68
+
69
+ ## Requirements
70
+
71
+ `pyfsda` does not bundle MATLAB or FSDA — it drives your local install. You need:
72
+
73
+ 1. **MATLAB** with the **FSDA Add-On** installed and on the MATLAB path (verify `which mahalFS`
74
+ inside MATLAB).
75
+ 2. **`matlabengine`** matching your MATLAB release. This is the one version constraint that matters:
76
+ the `matlabengine` package on PyPI is release-locked, so install the one that pairs with your
77
+ MATLAB — e.g. `pip install "matlabengine==26.1.*"` for **R2026a**. `pyfsda` lists `matlabengine`
78
+ as a dependency but deliberately does **not** pin it, so it will not clobber a matching version you
79
+ already have.
80
+ 3. **Python 3.9–3.13** (whatever your MATLAB release's engine supports).
81
+
82
+ ## Install
83
+
84
+ ```bash
85
+ pip install pyfsda
86
+ # then, if not already present, the matlabengine that matches YOUR MATLAB:
87
+ pip install "matlabengine==26.1.*" # example: MATLAB R2026a
88
+ ```
89
+
90
+ ## Verify your install
91
+
92
+ Run [`examples/smoke_test.py`](examples/smoke_test.py) — it starts MATLAB and checks a few real FSDA
93
+ routines against numpy oracles, printing `RESULT: PASS` when your MATLAB + FSDA + `matlabengine` setup
94
+ is good:
95
+
96
+ ```bash
97
+ python smoke_test.py # or: python smoke_test.py /path/to/FSDA
98
+ ```
99
+
100
+ For a worked, MATLAB-style example, see [`examples/score_example.py`](examples/score_example.py) — the
101
+ Box-Cox `Score` test on the wool dataset, calling `Score(y, X, 'la', ..., 'intercept', true)` the same
102
+ way you would in MATLAB.
103
+
104
+ ## What crosses the boundary
105
+
106
+ `call(name, *args, nargout=1, echo_output=False, options=None, **kwargs)` marshals positional
107
+ arguments in order and keyword arguments (and any `options` dict) as MATLAB name/value pairs. It runs
108
+ through the MATLAB workspace so outputs the engine cannot return directly (tables, 2-D cells) are
109
+ decoded MATLAB-side.
110
+
111
+ | MATLAB value | crosses as |
112
+ |---|---|
113
+ | numeric / logical array | `numpy.ndarray` (natural shape, `NaN`/`Inf` preserved) |
114
+ | `struct` | `dict` (recursed) |
115
+ | `char` / `string` scalar | `str` |
116
+ | `cell` | `list` |
117
+ | `table` / `timetable` | `dict` `{VariableNames, RowNames`/`RowTimes, data, height}` |
118
+ | 2-D `cell` | nested `list` |
119
+ | `nargout > 1` | `tuple` of the above |
120
+ | graphics handle (`matlab.graphics.*`) | **not marshalled** — request only data outputs |
121
+
122
+ Conventions: a 1-D input crosses as a MATLAB **row** (pass an `(n, 1)` array for a column); outputs
123
+ keep MATLAB's natural shape (no silent reshape); MATLAB indices stay **1-based**.
124
+
125
+ Reserved keywords consumed by the bridge are only `nargout`, `echo_output`, `options`, and `frames`;
126
+ every other keyword is forwarded to MATLAB (so FSDA's own `msg` option passes straight through).
127
+ `echo_output=True` tees MATLAB's stdout/stderr to your terminal.
128
+
129
+ ### Optional pandas view (`pip install pyfsda[pandas]`)
130
+
131
+ pandas is an **optional** dependency — `import pyfsda` works without it. When it is installed you get a
132
+ DataFrame view over MATLAB tables, on the Python side only (the neutral dict stays the default and
133
+ remains the cross-language contract):
134
+
135
+ - **Output:** pass `frames=True` to receive `table`/`timetable` outputs as a `pandas.DataFrame`
136
+ (index from `RowNames`/`RowTimes`) — e.g. `out = pyfsda.univariatems(y, X, frames=True)`. The public
137
+ helper `pyfsda.to_dataframe(table_dict)` converts a dict you already have.
138
+ - **Input:** pass a `pandas.DataFrame` argument and it is marshalled to a MATLAB `table`
139
+ (`array2table`, column names and any non-default index preserved). v1 covers numeric/logical columns;
140
+ string/categorical/datetime columns raise a clear `NotImplementedError`.
141
+
142
+ Requesting `frames=True` (or passing a DataFrame) without pandas installed raises a clear
143
+ `pip install pyfsda[pandas]` error.
144
+
145
+ On the **first `pyfsda.<name>(...)` call**, pyfsda also prints (once, best-effort) the **latest FSDA
146
+ release available on GitHub**, so you can check your install is current. `FsdaEngine.start()`
147
+ additionally runs a MATLAB-side FSDA up-to-date check via FSDA's `tuna` utility (quiet unless an update
148
+ is available). Both are gated by `check_version` — silence them with
149
+ `pyfsda.start(check_version=False)` (or `FsdaEngine.start(check_version=False)`) before the first call.
150
+
151
+ ## Notes
152
+
153
+ - **MATLAB engine startup is slow** — start one `FsdaEngine` and reuse it; always `stop()` explicitly.
154
+ - Struct-arrays and `datetime`/`duration` scalars are out of scope for the generic converters.
155
+
156
+ ## License
157
+
158
+ [EUPL-1.2](LICENSE) — consistent with FSDA's own licensing.