mindmap-synaptome 0.1.0__py3-none-any.whl

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 (64) hide show
  1. mindmap_synaptome-0.1.0.dist-info/METADATA +95 -0
  2. mindmap_synaptome-0.1.0.dist-info/RECORD +64 -0
  3. mindmap_synaptome-0.1.0.dist-info/WHEEL +4 -0
  4. mindmap_synaptome-0.1.0.dist-info/licenses/LICENSE +21 -0
  5. synaptome/__init__.py +34 -0
  6. synaptome/_utils.py +126 -0
  7. synaptome/datasets/__init__.py +35 -0
  8. synaptome/datasets/toy.py +983 -0
  9. synaptome/engine/__init__.py +99 -0
  10. synaptome/engine/bootstrap.py +461 -0
  11. synaptome/engine/cluster.py +261 -0
  12. synaptome/engine/correction.py +77 -0
  13. synaptome/engine/effect_sizes.py +368 -0
  14. synaptome/engine/ess.py +67 -0
  15. synaptome/engine/hypothesis.py +485 -0
  16. synaptome/engine/intervals.py +271 -0
  17. synaptome/estimates/__init__.py +10 -0
  18. synaptome/estimates/registry.py +329 -0
  19. synaptome/estimates/requirements.py +119 -0
  20. synaptome/estimates/run.py +412 -0
  21. synaptome/hypotheses/__init__.py +9 -0
  22. synaptome/hypotheses/registry.py +280 -0
  23. synaptome/hypotheses/run.py +559 -0
  24. synaptome/io/__init__.py +8 -0
  25. synaptome/io/_atomic.py +43 -0
  26. synaptome/io/syn.py +416 -0
  27. synaptome/plot/__init__.py +11 -0
  28. synaptome/plot/_data.py +499 -0
  29. synaptome/plot/_draw.py +604 -0
  30. synaptome/plot/accessor.py +932 -0
  31. synaptome/plot/figure.py +66 -0
  32. synaptome/plot/results.py +1051 -0
  33. synaptome/plot/style.py +113 -0
  34. synaptome/py.typed +0 -0
  35. synaptome/questions/__init__.py +25 -0
  36. synaptome/questions/base.py +484 -0
  37. synaptome/questions/compare.py +80 -0
  38. synaptome/questions/compare_along.py +43 -0
  39. synaptome/questions/design.py +137 -0
  40. synaptome/questions/distribution.py +39 -0
  41. synaptome/questions/fingerprint.py +65 -0
  42. synaptome/questions/resolve.py +468 -0
  43. synaptome/results/__init__.py +27 -0
  44. synaptome/results/base.py +396 -0
  45. synaptome/results/cluster.py +170 -0
  46. synaptome/results/correct.py +73 -0
  47. synaptome/results/describe.py +110 -0
  48. synaptome/results/estimate.py +149 -0
  49. synaptome/results/format.py +537 -0
  50. synaptome/results/normality.py +37 -0
  51. synaptome/results/omnibus.py +37 -0
  52. synaptome/results/pairwise.py +159 -0
  53. synaptome/results/run.py +54 -0
  54. synaptome/results/tested.py +72 -0
  55. synaptome/results/timing.py +51 -0
  56. synaptome/study/__init__.py +38 -0
  57. synaptome/study/attachments.py +176 -0
  58. synaptome/study/info.py +169 -0
  59. synaptome/study/protocol.py +368 -0
  60. synaptome/study/reduce.py +213 -0
  61. synaptome/study/study.py +991 -0
  62. synaptome/study/units.py +516 -0
  63. synaptome/study/values.py +117 -0
  64. synaptome/study/variables.py +717 -0
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.5
2
+ Name: mindmap-synaptome
3
+ Version: 0.1.0
4
+ Summary: Collect, store, and share all the metrics from a research study as one portable object.
5
+ Project-URL: Repository, https://github.com/NinoHerve/mindmap-synaptome
6
+ Project-URL: Documentation, https://ninoherve.github.io/mindmap-synaptome/
7
+ Author-email: Nino Herve <herve.nino@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: matplotlib>=3.7
16
+ Requires-Dist: numpy>=1.24
17
+ Requires-Dist: pandas>=2.0
18
+ Requires-Dist: pyarrow>=14
19
+ Requires-Dist: scipy>=1.10
20
+ Provides-Extra: dev
21
+ Requires-Dist: nbmake>=1.5; extra == 'dev'
22
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
23
+ Requires-Dist: pytest-mpl>=0.17; extra == 'dev'
24
+ Requires-Dist: pytest>=8; extra == 'dev'
25
+ Requires-Dist: ruff>=0.6; extra == 'dev'
26
+ Provides-Extra: docs
27
+ Requires-Dist: ipykernel>=6; extra == 'docs'
28
+ Requires-Dist: mkdocs-jupyter>=0.24; extra == 'docs'
29
+ Requires-Dist: mkdocs-material>=9; extra == 'docs'
30
+ Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
31
+ Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # mindmap-synaptome
35
+
36
+ Collect, store and share a research study's analysis-ready data as **one object**, and ask it questions:
37
+ tests, estimates and figures that know the study's design.
38
+
39
+ synaptome keeps every metric of a study (per subject, per trial, per time point, per source...) in a single
40
+ `Study`, with a data dictionary and the hierarchy of its units, saved as one `.syn` file anyone can open.
41
+ On top of it, you ask **questions** (what to compare, on which data) and synaptome works out the design:
42
+ paired or independent, which units are independent, which pairs have complete data. Tests and estimates
43
+ refuse what the design makes invalid and say what fits instead; results are plain values that carry their
44
+ question, settings and a fingerprint of the data they read.
45
+
46
+ ## Install
47
+
48
+ Part of the mindmap collection: installed as `mindmap-synaptome`, imported as `synaptome`.
49
+
50
+ ```bash
51
+ pip install git+https://github.com/NinoHerve/mindmap-synaptome # Python 3.10+
52
+ ```
53
+
54
+ ## Quickstart
55
+
56
+ ```python
57
+ import synaptome as syn
58
+
59
+ study = syn.datasets.method_comparison() # a toy study; syn.load("study.syn") for yours
60
+ q = study.compare("error", by="method", reference="proposed", subset={"sensors": "eeg"},
61
+ reduce={"source": "median"}, higher_is_better=False)
62
+ r = q.test("wilcoxon", alternative="less") # per pair, Holm-corrected, with effect sizes
63
+ print(r.to_markdown()) # an APA-style table for a paper
64
+ r.plot() # the groups, each subject joined, significance brackets
65
+ ```
66
+
67
+ With your own data, two pandas DataFrames are enough to start:
68
+
69
+ ```python
70
+ study = syn.Study("Weight trial")
71
+ study.add_units("subject", subjects) # columns: subject, group, age, ...
72
+ study.add("weight", weights) # columns: subject, week, weight
73
+ study.compare("weight", by="group", reduce={"week": "slope"}).test("welch").plot()
74
+ ```
75
+
76
+ ## What it does
77
+
78
+ - **One study, one file**: units in a hierarchy (nested or crossed), variables with dimensions, strict
79
+ validation, a `.syn` file of Parquet and JSON that any tool can read.
80
+ - **Questions that read the design**: paired or independent from where the factor lives, complete cases per
81
+ pair, guard rails against pseudo-replication and unreduced data.
82
+ - **Tests and estimates** with the right defaults: Wilcoxon, t-tests, McNemar, bootstrap, omnibus tests,
83
+ cluster permutation along a dimension, normality; effect sizes with intervals; corrections within and across
84
+ results; formatted tables.
85
+ - **Pre-registration**: questions written before the data, stored in the study; every result says whether its
86
+ question came first.
87
+ - **Figures** of data and results, drawing exactly what was tested.
88
+
89
+ ## Learn more
90
+
91
+ - [Documentation](https://ninoherve.github.io/mindmap-synaptome/): concepts, tutorials, API reference.
92
+ - [Tutorials](https://github.com/NinoHerve/mindmap-synaptome/blob/main/tutorials/README.md): runnable notebooks, from setup to pre-registration and plotting.
93
+ - [Changelog](https://github.com/NinoHerve/mindmap-synaptome/blob/main/CHANGELOG.md), [contributing](https://github.com/NinoHerve/mindmap-synaptome/blob/main/CONTRIBUTING.md).
94
+
95
+ mindmap-synaptome is released under the [MIT license](https://github.com/NinoHerve/mindmap-synaptome/blob/main/LICENSE).
@@ -0,0 +1,64 @@
1
+ synaptome/__init__.py,sha256=mXHPvMv5ieJnPJEcK0Xfq-pu4Ol8RWrKcWBY9WH3F58,791
2
+ synaptome/_utils.py,sha256=0BPf8NB_xDEvcZUk_3YDO8W2XqXCQH5CApglLRvAnDY,4345
3
+ synaptome/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ synaptome/datasets/__init__.py,sha256=DG6tnoMJnzm4NNx9m3wOZSBclbr7MaxtZvudS3s79L0,759
5
+ synaptome/datasets/toy.py,sha256=IOo_6GsrJYeKg_FpYylwG5mBUrdVHFl0t4arykiWhMY,37591
6
+ synaptome/engine/__init__.py,sha256=_OiQctehno-5p8mmKFu-85YmUWVyReRgAM7mW3LdOnY,2223
7
+ synaptome/engine/bootstrap.py,sha256=KF3u6KnXKZaNbq_wRiQRbapX9nzxSd1UgFEA5qrAELo,17129
8
+ synaptome/engine/cluster.py,sha256=SS8iAoTUiK0mK0X_dfxZVE8fXdnqun9GRVyYBzB3yNs,9887
9
+ synaptome/engine/correction.py,sha256=m7_ULu6yMM2g2cmtdD3uq8RClUO-2dPbCmEXHOl-SYE,2535
10
+ synaptome/engine/effect_sizes.py,sha256=ZtcwJzXli7KAdoNFylXJBZIu0LkuXwsz9QrL7C83i_A,13471
11
+ synaptome/engine/ess.py,sha256=OCHqYjp8w8iprCZLotAm5_oQOcdVy3NF3buVXYdzHwk,2002
12
+ synaptome/engine/hypothesis.py,sha256=T8GFzyYU_A_SwgRNOsdRANpF78L6KNfa-htZzcTzt3M,16962
13
+ synaptome/engine/intervals.py,sha256=M4ehbw6KsopFGjjXZiKyEHn9eNxZTAdeunSItRxau_4,9776
14
+ synaptome/estimates/__init__.py,sha256=HpQbqhgGnaOYHGj3LuAxmZ2NKQi8fJ3xrJ1qPL0nHFs,436
15
+ synaptome/estimates/registry.py,sha256=cM3M0oDeqTf_cJjPmirMG6G-gtNvmxBY79E6kEKMx8c,11175
16
+ synaptome/estimates/requirements.py,sha256=zCtIJaYUVl5iUQVTlPo_kLYCNBmV0VIogqHbIWo0RyM,4477
17
+ synaptome/estimates/run.py,sha256=g7fZZ6LSa4oysyZh1qL0_Ao5Pd97Bf3fq3JNce6pHf0,17560
18
+ synaptome/hypotheses/__init__.py,sha256=Mig9QylwZVmSTk_HQ326dtL2yB9pD2DkQg7nUL3OSJg,366
19
+ synaptome/hypotheses/registry.py,sha256=tYqAgtzJMBXy7w_J9jJs6yX9_OehobCPuMVXN6TIGfM,9797
20
+ synaptome/hypotheses/run.py,sha256=Rz0nzQ6daQLBIIkm9jOQ3uzdz9GW8irOKkVhjAQmGGo,24448
21
+ synaptome/io/__init__.py,sha256=092u1zkW1Quc4lcGaWGfFpk42yaKDB5ciRnvx9l_aGc,205
22
+ synaptome/io/_atomic.py,sha256=5AWK_brWmobQ_M7DycJV7cX10IeNdNctJxjWm6Yqk_g,1368
23
+ synaptome/io/syn.py,sha256=JrZJoZiMeS3s4qgwuTgx6nizIQS3Jo5GVCc9GHgKMgE,14971
24
+ synaptome/plot/__init__.py,sha256=mQaA8EBFl87ulr5RpwpxYTR3TYzTOYQpULx3xmTE7ps,400
25
+ synaptome/plot/_data.py,sha256=27xEDRJl6EzeuhyERJJ5FTaJFRwlXyS7kf9s5oPqPPU,20243
26
+ synaptome/plot/_draw.py,sha256=HcO5HbCXtRDl8FqkyzlB8VGi8Zbi90QLXMa9Y1qP3RQ,23901
27
+ synaptome/plot/accessor.py,sha256=h3eiOWt0wN6j5Bs5f2kmf8ZQ6bBTAj8pGjanCj3Nujc,38343
28
+ synaptome/plot/figure.py,sha256=YyAkXspOz7Zycn6TU_lybnUArMCP7cTLaEw6YafhYAw,1919
29
+ synaptome/plot/results.py,sha256=9gcwH3bRiD93Oc8Dyh7pqdlqHNWbWQTAVELoDRqe36s,44931
30
+ synaptome/plot/style.py,sha256=_tBp6BgUeKWGWldH0IXmscQ7_Kfc_yWXy9FWF16MP70,4413
31
+ synaptome/questions/__init__.py,sha256=SP05HUW9nKA3t_tDrVLBlGYecu5QBySh-wOOfSTCCM8,730
32
+ synaptome/questions/base.py,sha256=8HA18L4fuuJmIi4WJPVxZ0u9NoUpqtY4DSSMtrh8LmI,19031
33
+ synaptome/questions/compare.py,sha256=iYzr-Rl2OPc_mWIwtVgb2SMDbrSCY1XkzC7XOjAk3wA,3327
34
+ synaptome/questions/compare_along.py,sha256=ff3NN-qZtr8-AwXwMY6JwyuQBez09JA0GtROaDxBoHk,1571
35
+ synaptome/questions/design.py,sha256=Dc6UVobc7_pLwrqtT8z9O7IR8HIrvC4BXUDzciNfTUk,5791
36
+ synaptome/questions/distribution.py,sha256=TBy1oKtzboGjQ-GL3IXSMzWy2kj7HTHN39Bf-5Hx5eE,1156
37
+ synaptome/questions/fingerprint.py,sha256=1BeiW-4uNyQqo-JsYmNie3bmM3x6ivCyYmqrMVbndnk,2315
38
+ synaptome/questions/resolve.py,sha256=lg4d40d-8L7O6aWaG9pwhK78yZXE5bYu7hcaqBEFHfw,19818
39
+ synaptome/results/__init__.py,sha256=Wi4KeEJqea2KcY2VNMBsZykYtRsW9O6vLVAerAX7AH4,779
40
+ synaptome/results/base.py,sha256=lGY9KR4kBaJQgqerfyKOQ5cz8IG3Ysc-QzeVR-dpK0E,13857
41
+ synaptome/results/cluster.py,sha256=iz3pLfYgzjipow0lgxenCYygu-bnwGV3LvYe4W43r6o,7199
42
+ synaptome/results/correct.py,sha256=wctOBknWxB7YJfhLBRo5HgrnPhdJwvrVCiUUZf82KbE,2707
43
+ synaptome/results/describe.py,sha256=PcoDSrTZO3gY5sn7zBYVimOM-JD-lmajs0Ob7ubFdis,4157
44
+ synaptome/results/estimate.py,sha256=RQsvBbIvy2AUI0buv3bDO6ZRYV2jebsVboQTo5cFy6o,5240
45
+ synaptome/results/format.py,sha256=EtsDIwtAVupZINi2jWmhaWfJMCTZI5cnLmcTGlsNdQg,20916
46
+ synaptome/results/normality.py,sha256=0cQPOrNEUADby1BfN8hOOWKEmytr8A24GfD1Dg2AP-s,1182
47
+ synaptome/results/omnibus.py,sha256=d7U1BNp1noRR6pZlXquffRY7qnQ4t_B4CMqDHBZGR2E,1096
48
+ synaptome/results/pairwise.py,sha256=WyUO0_XGmNQxCvT3DcZUtuxYGPZQNCZxPVC-z-qoF00,6767
49
+ synaptome/results/run.py,sha256=-9rrndazGfEyQiNCEQOVUFsrh-d87gLEh5zYfycDy50,1682
50
+ synaptome/results/tested.py,sha256=_QJ_abFecB93XQ137pyxP2q5L7Ukt4sM9oa_SZYAqzs,2378
51
+ synaptome/results/timing.py,sha256=E29MtFNhWMz5QSh4N6KKtdLwJqjYRb3du7DDc4IDidY,1980
52
+ synaptome/study/__init__.py,sha256=mvq8ONlaAhdPrUWjFZTNJnCFoTErwVf_yEi_bm3jmDE,892
53
+ synaptome/study/attachments.py,sha256=LY9oxvF6kR2ifAT1ztSLL4QAuPRKy1Yl1jIZp38863k,5308
54
+ synaptome/study/info.py,sha256=Xutp2zTsoGT6TVRgI2NaG_78XJ8KKYpZqd9tidcd4Dk,6098
55
+ synaptome/study/protocol.py,sha256=jzJhGf3bYfFBCYVN1ObOni3Zn52G9QRbB19FBqvJbTw,14555
56
+ synaptome/study/reduce.py,sha256=x0V09sg__R1dgSImeK4vsnW8pQdwj7iCsgCiKrxqFII,8351
57
+ synaptome/study/study.py,sha256=5oxxOuAmwj7GJQwAqI2nw08Qu7YkNEBUxUnofA2ot1s,42028
58
+ synaptome/study/units.py,sha256=s6uNIGQle_ObWEO4nyfOfFe92n7zDfg5Y4KyKTdqGgU,22222
59
+ synaptome/study/values.py,sha256=d6P_AObSSvpM0hCLH-angaCocpK8Fe0IVlQvcdo65JM,4490
60
+ synaptome/study/variables.py,sha256=QMJ-8_8FxTLcMihwB0VAzXVLDRbnEOwA9hMX3Ut7t44,30577
61
+ mindmap_synaptome-0.1.0.dist-info/METADATA,sha256=vQbeEvIcC8trBl1YPh9ABOarq0sPv-BPudoeURwwNEc,4631
62
+ mindmap_synaptome-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
63
+ mindmap_synaptome-0.1.0.dist-info/licenses/LICENSE,sha256=SKlQP_VTmwzy9Z5K92qousTroZ4Fyc2LixpKwgEUHbo,1067
64
+ mindmap_synaptome-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nino Herve
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.
synaptome/__init__.py ADDED
@@ -0,0 +1,34 @@
1
+ """
2
+ synaptome -- collect, store, and share all the metrics from a research study
3
+ as one portable object, with statistics and plots on demand.
4
+ """
5
+
6
+ from . import datasets
7
+ from .io import load, peek
8
+ from .results import correct, load_result
9
+ from .study import InferenceNotice, Study, concat
10
+
11
+ __version__ = "0.1.0"
12
+
13
+
14
+ def __getattr__(name: str):
15
+ # `synaptome.plot` is imported on first use, so `import synaptome` doesn't load matplotlib.
16
+ if name == "plot":
17
+ import importlib
18
+
19
+ return importlib.import_module(".plot", __name__)
20
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
21
+
22
+
23
+ __all__ = [
24
+ "InferenceNotice",
25
+ "Study",
26
+ "__version__",
27
+ "concat",
28
+ "correct",
29
+ "datasets",
30
+ "load",
31
+ "load_result",
32
+ "peek",
33
+ "plot",
34
+ ]
synaptome/_utils.py ADDED
@@ -0,0 +1,126 @@
1
+ """
2
+ Small helpers shared across the package: telling scalars from array-likes,
3
+ making values JSON-safe, and freezing filter arguments into hashable,
4
+ JSON-round-trippable keys (used for stats caching and persistence).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import math
10
+ from collections.abc import Mapping
11
+ from typing import Any
12
+
13
+ import numpy as np
14
+ import pandas as pd
15
+
16
+ _ARRAYLIKE_TYPES = (list, tuple, np.ndarray, pd.Series, pd.Index)
17
+
18
+
19
+ def is_arraylike(val: Any) -> bool:
20
+ """Whether `val` should be treated as a sequence of values rather than a scalar tag."""
21
+ return isinstance(val, _ARRAYLIKE_TYPES)
22
+
23
+
24
+ def json_safe(val: Any) -> Any:
25
+ """
26
+ Converts numpy/pandas scalars into plain Python types that `json.dump`
27
+ accepts (`np.float64` -> `float`, `np.bool_` -> `bool`, `pd.Timestamp`
28
+ -> ISO string, ...). Anything else is returned unchanged.
29
+
30
+ Usable directly as `json.dump(..., default=json_safe)` too: in that
31
+ role it is only called on objects `json` can't serialize itself, and
32
+ raises `TypeError` for anything it can't convert either.
33
+ """
34
+ if isinstance(val, np.generic):
35
+ return val.item()
36
+ if isinstance(val, pd.Timestamp):
37
+ return val.isoformat()
38
+ return val
39
+
40
+
41
+ def json_default(val: Any) -> Any:
42
+ """`json.dump(..., default=json_default)` hook: converts what it can, raises otherwise."""
43
+ converted = json_safe(val)
44
+ if converted is val:
45
+ raise TypeError(f"Object of type {type(val).__name__} is not JSON serializable.")
46
+ return converted
47
+
48
+
49
+ def freeze_filter(val: Any) -> tuple | None:
50
+ """
51
+ Normalizes a scalar-or-sequence-or-None argument into a hashable tuple:
52
+ `None` stays `None`, a scalar becomes a 1-tuple, a sequence becomes a
53
+ tuple of JSON-safe scalars (order preserved).
54
+ """
55
+ if val is None:
56
+ return None
57
+ if is_arraylike(val):
58
+ return tuple(json_safe(v) for v in val)
59
+ return (json_safe(val),)
60
+
61
+
62
+ def sorted_filter(val: Any) -> tuple | None:
63
+ """Same as `freeze_filter`, but sorted first -- for value sets where order doesn't matter."""
64
+ if not is_arraylike(val):
65
+ return freeze_filter(val)
66
+ return freeze_filter(sorted(val, key=_sort_key))
67
+
68
+
69
+ def freeze_filters(filters: Mapping[str, Any] | None) -> tuple | None:
70
+ """
71
+ Normalizes a `{column: value(s)}` filter dict into a hashable,
72
+ key-order-independent tuple `((column, (v1, v2, ...)), ...)`, sorted by
73
+ column. `None` or empty gives `None`.
74
+ """
75
+ if not filters:
76
+ return None
77
+ return tuple(sorted((k, sorted_filter(v)) for k, v in filters.items()))
78
+
79
+
80
+ def filters_to_json(frozen: tuple | None) -> list | None:
81
+ """`freeze_filters` output -> JSON-safe nested lists."""
82
+ if not frozen:
83
+ return None
84
+ return [[k, list(v) if v is not None else None] for k, v in frozen]
85
+
86
+
87
+ def filters_from_json(data: list | None) -> tuple | None:
88
+ """Inverse of `filters_to_json`."""
89
+ if not data:
90
+ return None
91
+ return tuple((k, tuple(v) if v is not None else None) for k, v in data)
92
+
93
+
94
+ def filters_to_dict(frozen: tuple | None) -> dict:
95
+ """`freeze_filters` output -> a plain `{column: [values]}` dict, usable as `filters=` again."""
96
+ if not frozen:
97
+ return {}
98
+ return {k: list(v) if v is not None else None for k, v in frozen}
99
+
100
+
101
+ def match_values(series: pd.Series, vals: Any) -> np.ndarray:
102
+ """
103
+ Boolean mask of the entries of `series` matching `vals`: a single value, a list of values, or a
104
+ `slice(low, high)` (inclusive; either end may be None; no step).
105
+ """
106
+ if isinstance(vals, slice):
107
+ if vals.step is not None:
108
+ raise ValueError("Coordinate slices can't have a step.")
109
+ hit = np.ones(len(series), dtype=bool)
110
+ if vals.start is not None:
111
+ hit &= (series >= vals.start).to_numpy()
112
+ if vals.stop is not None:
113
+ hit &= (series <= vals.stop).to_numpy()
114
+ return hit
115
+ wanted = list(vals) if is_arraylike(vals) else [vals]
116
+ return series.isin(wanted).to_numpy()
117
+
118
+
119
+ def _sort_key(v: Any) -> tuple:
120
+ """Total order over mixed scalars (numbers before strings, NaN/None last) so sorting never raises."""
121
+ v = json_safe(v)
122
+ if v is None or (isinstance(v, float) and math.isnan(v)):
123
+ return (2, "")
124
+ if isinstance(v, (bool, int, float)):
125
+ return (0, v)
126
+ return (1, str(v))
@@ -0,0 +1,35 @@
1
+ """
2
+ Toy studies with planted effects, one generator per study type (DESIGN.md section 13).
3
+
4
+ Each function returns a new, seeded `Study`; its planted effects (real and null) are listed in its
5
+ docstring and in `study.info.extra["planted"]`.
6
+
7
+ ```python
8
+ >>> import synaptome as syn
9
+ >>> study = syn.datasets.crossover(n_subjects=24, seed=1)
10
+ >>> study.info.extra["planted"][0]["value"]
11
+ 5.0
12
+ ```
13
+ """
14
+
15
+ from .toy import (
16
+ case_control,
17
+ crossed,
18
+ crossover,
19
+ longitudinal,
20
+ method_comparison,
21
+ repeated_trials,
22
+ simulation_benchmark,
23
+ timepoint_pairing,
24
+ )
25
+
26
+ __all__ = [
27
+ "case_control",
28
+ "crossed",
29
+ "crossover",
30
+ "longitudinal",
31
+ "method_comparison",
32
+ "repeated_trials",
33
+ "simulation_benchmark",
34
+ "timepoint_pairing",
35
+ ]