statstudio 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.
- statstudio/__init__.py +9 -0
- statstudio/__main__.py +3 -0
- statstudio/app.py +83 -0
- statstudio/cli.py +116 -0
- statstudio/core/__init__.py +3 -0
- statstudio/core/archive.py +27 -0
- statstudio/core/commands.py +67 -0
- statstudio/core/formula_catalog.py +74 -0
- statstudio/core/formulas.py +605 -0
- statstudio/core/joins.py +123 -0
- statstudio/core/project.py +358 -0
- statstudio/core/runtime.py +321 -0
- statstudio/core/scripting.py +594 -0
- statstudio/core/table.py +796 -0
- statstudio/core/transform.py +450 -0
- statstudio/feature_help.py +595 -0
- statstudio/io/__init__.py +3 -0
- statstudio/io/docx.py +201 -0
- statstudio/io/export.py +99 -0
- statstudio/io/file_import.py +199 -0
- statstudio/io/odbc.py +334 -0
- statstudio/io/sample_data.py +164 -0
- statstudio/io/table_io.py +118 -0
- statstudio/plots/__init__.py +19 -0
- statstudio/plots/advanced.py +651 -0
- statstudio/plots/basic.py +957 -0
- statstudio/plots/bayesian_plots.py +94 -0
- statstudio/plots/common.py +334 -0
- statstudio/plots/diagnostics.py +214 -0
- statstudio/plots/doe_plots.py +235 -0
- statstudio/plots/plotly_builders.py +719 -0
- statstudio/plots/predictive_plots.py +72 -0
- statstudio/plots/registry.py +251 -0
- statstudio/plugins.py +111 -0
- statstudio/resources/help_topics.json +13195 -0
- statstudio/resources/logo.ico +0 -0
- statstudio/resources/logo.png +0 -0
- statstudio/resources/statstudio.svg +8 -0
- statstudio/stats/__init__.py +42 -0
- statstudio/stats/bayesian.py +1094 -0
- statstudio/stats/bayesian_optimization.py +590 -0
- statstudio/stats/common.py +140 -0
- statstudio/stats/correlation.py +135 -0
- statstudio/stats/custom_doe.py +1714 -0
- statstudio/stats/descriptive.py +200 -0
- statstudio/stats/desirability.py +132 -0
- statstudio/stats/distributions.py +331 -0
- statstudio/stats/doe.py +1070 -0
- statstudio/stats/hypothesis.py +1305 -0
- statstudio/stats/multivariate.py +307 -0
- statstudio/stats/optimal_doe.py +264 -0
- statstudio/stats/power.py +194 -0
- statstudio/stats/predictive.py +605 -0
- statstudio/stats/profiler.py +379 -0
- statstudio/stats/quality.py +1218 -0
- statstudio/stats/regression.py +1600 -0
- statstudio/stats/results.py +235 -0
- statstudio/stats/simulator.py +95 -0
- statstudio/stats/survival.py +637 -0
- statstudio/stats/timeseries.py +643 -0
- statstudio/stats/tolerance.py +154 -0
- statstudio/ui/__init__.py +0 -0
- statstudio/ui/analysis_hub.py +271 -0
- statstudio/ui/command_catalog.py +460 -0
- statstudio/ui/command_palette.py +55 -0
- statstudio/ui/console.py +239 -0
- statstudio/ui/dialogs/__init__.py +0 -0
- statstudio/ui/dialogs/advanced_dialogs.py +392 -0
- statstudio/ui/dialogs/base.py +537 -0
- statstudio/ui/dialogs/bayesian_dialogs.py +488 -0
- statstudio/ui/dialogs/bayesian_optimization_dialog.py +299 -0
- statstudio/ui/dialogs/custom_doe_dialog.py +467 -0
- statstudio/ui/dialogs/doe_dialogs.py +220 -0
- statstudio/ui/dialogs/extended_dialogs.py +665 -0
- statstudio/ui/dialogs/graph_builder.py +139 -0
- statstudio/ui/dialogs/help_dialog.py +207 -0
- statstudio/ui/dialogs/help_topics.py +280 -0
- statstudio/ui/dialogs/lazy.py +184 -0
- statstudio/ui/dialogs/odbc_dialog.py +311 -0
- statstudio/ui/dialogs/plot_dialog.py +1385 -0
- statstudio/ui/dialogs/report_composer.py +218 -0
- statstudio/ui/dialogs/script_dialogs.py +267 -0
- statstudio/ui/dialogs/stats_dialogs.py +1688 -0
- statstudio/ui/dialogs/table_dialogs.py +997 -0
- statstudio/ui/dialogs/window.py +58 -0
- statstudio/ui/docks/__init__.py +0 -0
- statstudio/ui/formula_editor.py +121 -0
- statstudio/ui/icons.py +257 -0
- statstudio/ui/jobs.py +179 -0
- statstudio/ui/main_window.py +3934 -0
- statstudio/ui/plot_interaction.py +178 -0
- statstudio/ui/profiler_widget.py +437 -0
- statstudio/ui/recent.py +82 -0
- statstudio/ui/reports/__init__.py +0 -0
- statstudio/ui/reports/report_view.py +1632 -0
- statstudio/ui/script_jobs.py +35 -0
- statstudio/ui/scripts_panel.py +271 -0
- statstudio/ui/table_document.py +233 -0
- statstudio/ui/table_model.py +285 -0
- statstudio/ui/table_view.py +285 -0
- statstudio/ui/theme.py +645 -0
- statstudio/ui/welcome.py +453 -0
- statstudio/ui/window_controls.py +53 -0
- statstudio/ui/workers.py +53 -0
- statstudio-0.1.0.dist-info/METADATA +261 -0
- statstudio-0.1.0.dist-info/RECORD +110 -0
- statstudio-0.1.0.dist-info/WHEEL +5 -0
- statstudio-0.1.0.dist-info/entry_points.txt +5 -0
- statstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
- statstudio-0.1.0.dist-info/top_level.txt +1 -0
statstudio/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
# Copyright (C) 2026 P Aryal
|
|
3
|
+
|
|
4
|
+
"""StatStudio: a statistical analysis desktop environment."""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
__author__ = "P Aryal"
|
|
8
|
+
__license__ = "GPL-3.0-or-later"
|
|
9
|
+
__copyright__ = "Copyright (C) 2026 P Aryal"
|
statstudio/__main__.py
ADDED
statstudio/app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import threading
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
os.environ.setdefault("QT_API", "pyside6")
|
|
9
|
+
os.environ.setdefault("MPLBACKEND", "QtAgg")
|
|
10
|
+
|
|
11
|
+
from PySide6.QtCore import QLibraryInfo, Qt
|
|
12
|
+
from PySide6.QtGui import QIcon
|
|
13
|
+
from PySide6.QtWidgets import QApplication, QProgressDialog
|
|
14
|
+
|
|
15
|
+
from statstudio import plugins
|
|
16
|
+
from statstudio.ui import theme
|
|
17
|
+
|
|
18
|
+
ICON_PATH = Path(__file__).parent / "resources" / "logo.png"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def application_icon() -> QIcon:
|
|
22
|
+
return QIcon(str(ICON_PATH))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _configure_qt_platform() -> None:
|
|
26
|
+
if not sys.platform.startswith("linux") or os.environ.get("QT_QPA_PLATFORM"):
|
|
27
|
+
return
|
|
28
|
+
if os.environ.get("XDG_SESSION_TYPE") != "wayland" and not os.environ.get("WAYLAND_DISPLAY"):
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
plugin_dir = Path(QLibraryInfo.path(QLibraryInfo.LibraryPath.PluginsPath)) / "platforms"
|
|
32
|
+
if any(plugin_dir.glob("libqwayland*.so")):
|
|
33
|
+
return
|
|
34
|
+
if (plugin_dir / "libqxcb.so").is_file():
|
|
35
|
+
os.environ["QT_QPA_PLATFORM"] = "xcb"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _discover_plugins() -> None:
|
|
39
|
+
thread = threading.Thread(target=plugins.registry.discover, name="statstudio-plugins", daemon=True)
|
|
40
|
+
thread.start()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main() -> None:
|
|
44
|
+
_configure_qt_platform()
|
|
45
|
+
app = QApplication(sys.argv)
|
|
46
|
+
app.setApplicationName("StatStudio")
|
|
47
|
+
app.setOrganizationName("StatStudio")
|
|
48
|
+
app.setDesktopFileName("statstudio")
|
|
49
|
+
app.setStyle("Fusion")
|
|
50
|
+
theme.apply_theme(app, theme.load_saved_theme())
|
|
51
|
+
icon = application_icon()
|
|
52
|
+
if not icon.isNull():
|
|
53
|
+
app.setWindowIcon(icon)
|
|
54
|
+
|
|
55
|
+
progress = QProgressDialog("Starting StatStudio...", "", 0, 100)
|
|
56
|
+
progress.setWindowTitle("StatStudio")
|
|
57
|
+
progress.setCancelButton(None)
|
|
58
|
+
progress.setWindowFlag(Qt.WindowType.SplashScreen, True)
|
|
59
|
+
progress.setMinimumDuration(0)
|
|
60
|
+
progress.setValue(10)
|
|
61
|
+
app.processEvents()
|
|
62
|
+
|
|
63
|
+
from statstudio.core.project import Project
|
|
64
|
+
from statstudio.ui.main_window import MainWindow
|
|
65
|
+
|
|
66
|
+
progress.setLabelText("Loading the workspace...")
|
|
67
|
+
progress.setValue(55)
|
|
68
|
+
app.processEvents()
|
|
69
|
+
window = MainWindow(Project())
|
|
70
|
+
if not icon.isNull():
|
|
71
|
+
window.setWindowIcon(icon)
|
|
72
|
+
progress.setLabelText("Opening the project...")
|
|
73
|
+
progress.setValue(85)
|
|
74
|
+
app.processEvents()
|
|
75
|
+
window.show()
|
|
76
|
+
progress.setValue(100)
|
|
77
|
+
progress.close()
|
|
78
|
+
_discover_plugins()
|
|
79
|
+
sys.exit(app.exec())
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
main()
|
statstudio/cli.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from statstudio.core.project import Project, ProjectFileError
|
|
9
|
+
from statstudio.io.table_io import TABLE_SUFFIX, TableFileError, load_table
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _parser() -> argparse.ArgumentParser:
|
|
13
|
+
parser = argparse.ArgumentParser(prog="statstudio", description="StatStudio launcher and headless runner")
|
|
14
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
15
|
+
|
|
16
|
+
run = subparsers.add_parser("run", help="Run a Python script headlessly")
|
|
17
|
+
run.add_argument("script", type=Path)
|
|
18
|
+
run.add_argument("--project", type=Path, default=None)
|
|
19
|
+
run.add_argument("--table", type=Path, default=None, help=f"Load a {TABLE_SUFFIX} as `table` and in `_tables`")
|
|
20
|
+
run.add_argument("--save-project", type=Path, default=None)
|
|
21
|
+
run.add_argument("--headless", action="store_true", help="Accepted for compatibility; run is always headless")
|
|
22
|
+
|
|
23
|
+
replay = subparsers.add_parser("replay", help="Replay a project's analysis journal headlessly")
|
|
24
|
+
replay.add_argument("project", type=Path)
|
|
25
|
+
replay.add_argument("--save-project", type=Path, default=None)
|
|
26
|
+
replay.add_argument("--headless", action="store_true", help="Accepted for compatibility; replay is always headless")
|
|
27
|
+
replay.add_argument(
|
|
28
|
+
"--trust",
|
|
29
|
+
action="store_true",
|
|
30
|
+
help="Allow replaying journal code embedded in the project file",
|
|
31
|
+
)
|
|
32
|
+
return parser
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _load_project(path: Path | None) -> Project:
|
|
36
|
+
if path is None:
|
|
37
|
+
return Project()
|
|
38
|
+
if path.exists():
|
|
39
|
+
return Project.load(path)
|
|
40
|
+
return Project(name=path.stem, path=path)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _run(args) -> int:
|
|
44
|
+
os.environ.setdefault("MPLBACKEND", "Agg")
|
|
45
|
+
from statstudio.core import runtime
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
project = _load_project(args.project)
|
|
49
|
+
table = None
|
|
50
|
+
if args.table is not None:
|
|
51
|
+
table = load_table(args.table)
|
|
52
|
+
project.add_table(table)
|
|
53
|
+
output, ok = runtime.run_script_file(project, args.script, table=table)
|
|
54
|
+
except (OSError, ProjectFileError, TableFileError, ValueError) as exc:
|
|
55
|
+
print(f"statstudio: {exc}", file=sys.stderr)
|
|
56
|
+
return 1
|
|
57
|
+
if output:
|
|
58
|
+
print(output)
|
|
59
|
+
if not ok:
|
|
60
|
+
return 1
|
|
61
|
+
if args.save_project is not None:
|
|
62
|
+
try:
|
|
63
|
+
project.save(args.save_project)
|
|
64
|
+
except OSError as exc:
|
|
65
|
+
print(f"statstudio: could not save project: {exc}", file=sys.stderr)
|
|
66
|
+
return 1
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _replay(args) -> int:
|
|
71
|
+
os.environ.setdefault("MPLBACKEND", "Agg")
|
|
72
|
+
from statstudio.core import runtime, scripting
|
|
73
|
+
|
|
74
|
+
if not args.trust:
|
|
75
|
+
print(
|
|
76
|
+
"statstudio: replaying a project journal can execute arbitrary Python. "
|
|
77
|
+
"Re-run with --trust only for projects you trust.",
|
|
78
|
+
file=sys.stderr,
|
|
79
|
+
)
|
|
80
|
+
return 2
|
|
81
|
+
try:
|
|
82
|
+
project = Project.load(args.project)
|
|
83
|
+
code = scripting.cumulative_script(project, str(args.project))
|
|
84
|
+
namespace = runtime.build_namespace(project)
|
|
85
|
+
output, ok = runtime.execute_code(code, namespace, filename="<journal-replay>", capture_errors=True)
|
|
86
|
+
except (OSError, ProjectFileError, ValueError) as exc:
|
|
87
|
+
print(f"statstudio: {exc}", file=sys.stderr)
|
|
88
|
+
return 1
|
|
89
|
+
if output:
|
|
90
|
+
print(output)
|
|
91
|
+
if not ok:
|
|
92
|
+
return 1
|
|
93
|
+
runtime.sync_tables(project, namespace)
|
|
94
|
+
if args.save_project is not None:
|
|
95
|
+
try:
|
|
96
|
+
project.save(args.save_project)
|
|
97
|
+
except OSError as exc:
|
|
98
|
+
print(f"statstudio: could not save project: {exc}", file=sys.stderr)
|
|
99
|
+
return 1
|
|
100
|
+
return 0
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def main(argv: list[str] | None = None) -> int:
|
|
104
|
+
parser = _parser()
|
|
105
|
+
args = parser.parse_args(argv)
|
|
106
|
+
from statstudio import plugins
|
|
107
|
+
|
|
108
|
+
plugins.registry.discover()
|
|
109
|
+
if args.command == "run":
|
|
110
|
+
return _run(args)
|
|
111
|
+
if args.command == "replay":
|
|
112
|
+
return _replay(args)
|
|
113
|
+
from statstudio.app import main as gui_main
|
|
114
|
+
|
|
115
|
+
gui_main()
|
|
116
|
+
return 0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import zipfile
|
|
4
|
+
|
|
5
|
+
MAX_ARCHIVE_MEMBERS = 10_000
|
|
6
|
+
MAX_ARCHIVE_BYTES = 4 * 1024 * 1024 * 1024
|
|
7
|
+
MAX_JSON_BYTES = 64 * 1024 * 1024
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def validate_archive(archive: zipfile.ZipFile, error_type: type[Exception] = ValueError) -> None:
|
|
11
|
+
infos = archive.infolist()
|
|
12
|
+
if len(infos) > MAX_ARCHIVE_MEMBERS:
|
|
13
|
+
raise error_type("The archive contains too many members.")
|
|
14
|
+
total = 0
|
|
15
|
+
for info in infos:
|
|
16
|
+
if info.file_size > MAX_ARCHIVE_BYTES:
|
|
17
|
+
raise error_type(f"Archive member {info.filename!r} is too large.")
|
|
18
|
+
total += info.file_size
|
|
19
|
+
if total > MAX_ARCHIVE_BYTES:
|
|
20
|
+
raise error_type("The archive expands to more data than StatStudio can safely load.")
|
|
21
|
+
for name in ("project.json", "table.json"):
|
|
22
|
+
try:
|
|
23
|
+
info = archive.getinfo(name)
|
|
24
|
+
except KeyError:
|
|
25
|
+
continue
|
|
26
|
+
if info.file_size > MAX_JSON_BYTES:
|
|
27
|
+
raise error_type(f"{name} is too large.")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Callable
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class Command:
|
|
9
|
+
label: str
|
|
10
|
+
undo: Callable[[], None]
|
|
11
|
+
redo: Callable[[], None]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CommandStack:
|
|
15
|
+
def __init__(self, limit: int = 100) -> None:
|
|
16
|
+
self.limit = limit
|
|
17
|
+
self._undo: list[Command] = []
|
|
18
|
+
self._redo: list[Command] = []
|
|
19
|
+
|
|
20
|
+
def push(self, command: Command) -> None:
|
|
21
|
+
self._undo.append(command)
|
|
22
|
+
if len(self._undo) > self.limit:
|
|
23
|
+
self._undo.pop(0)
|
|
24
|
+
self._redo.clear()
|
|
25
|
+
|
|
26
|
+
def record(self, label: str, before: Callable[[], None], after: Callable[[], None]) -> None:
|
|
27
|
+
self.push(Command(label=label, undo=before, redo=after))
|
|
28
|
+
|
|
29
|
+
def can_undo(self) -> bool:
|
|
30
|
+
return bool(self._undo)
|
|
31
|
+
|
|
32
|
+
def can_redo(self) -> bool:
|
|
33
|
+
return bool(self._redo)
|
|
34
|
+
|
|
35
|
+
def undo_label(self) -> str | None:
|
|
36
|
+
return self._undo[-1].label if self._undo else None
|
|
37
|
+
|
|
38
|
+
def redo_label(self) -> str | None:
|
|
39
|
+
return self._redo[-1].label if self._redo else None
|
|
40
|
+
|
|
41
|
+
def undo(self) -> str | None:
|
|
42
|
+
if not self._undo:
|
|
43
|
+
return None
|
|
44
|
+
command = self._undo.pop()
|
|
45
|
+
try:
|
|
46
|
+
command.undo()
|
|
47
|
+
except Exception:
|
|
48
|
+
self._undo.append(command)
|
|
49
|
+
raise
|
|
50
|
+
self._redo.append(command)
|
|
51
|
+
return command.label
|
|
52
|
+
|
|
53
|
+
def redo(self) -> str | None:
|
|
54
|
+
if not self._redo:
|
|
55
|
+
return None
|
|
56
|
+
command = self._redo.pop()
|
|
57
|
+
try:
|
|
58
|
+
command.redo()
|
|
59
|
+
except Exception:
|
|
60
|
+
self._redo.append(command)
|
|
61
|
+
raise
|
|
62
|
+
self._undo.append(command)
|
|
63
|
+
return command.label
|
|
64
|
+
|
|
65
|
+
def clear(self) -> None:
|
|
66
|
+
self._undo.clear()
|
|
67
|
+
self._redo.clear()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass(frozen=True)
|
|
7
|
+
class FormulaEntry:
|
|
8
|
+
name: str
|
|
9
|
+
category: str
|
|
10
|
+
signature: str
|
|
11
|
+
description: str
|
|
12
|
+
example: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
FORMULA_ENTRIES: tuple[FormulaEntry, ...] = (
|
|
16
|
+
FormulaEntry("abs", "Math", "abs(value)", "Absolute value.", 'abs(col("x"))'),
|
|
17
|
+
FormulaEntry("sqrt", "Math", "sqrt(value)", "Square root.", 'sqrt(col("x"))'),
|
|
18
|
+
FormulaEntry("exp", "Math", "exp(value)", "Exponential, e raised to the value.", 'exp(col("x"))'),
|
|
19
|
+
FormulaEntry("log", "Math", "log(value)", "Natural logarithm.", 'log(col("x"))'),
|
|
20
|
+
FormulaEntry("ln", "Math", "ln(value)", "Natural logarithm.", 'ln(col("x"))'),
|
|
21
|
+
FormulaEntry("log10", "Math", "log10(value)", "Base-10 logarithm.", 'log10(col("x"))'),
|
|
22
|
+
FormulaEntry("log2", "Math", "log2(value)", "Base-2 logarithm.", 'log2(col("x"))'),
|
|
23
|
+
FormulaEntry("pow", "Math", "value ** power", "Raise a value to a power.", 'col("x") ** 2'),
|
|
24
|
+
FormulaEntry("floor", "Math", "floor(value)", "Round down to an integer.", 'floor(col("x"))'),
|
|
25
|
+
FormulaEntry("ceil", "Math", "ceil(value)", "Round up to an integer.", 'ceil(col("x"))'),
|
|
26
|
+
FormulaEntry("round", "Math", "round(value, decimals=0)", "Round to a number of decimal places.", 'round(col("x"), 2)'),
|
|
27
|
+
FormulaEntry("minimum", "Math", "minimum(a, b)", "Smaller of two values.", 'minimum(col("x"), col("y"))'),
|
|
28
|
+
FormulaEntry("maximum", "Math", "maximum(a, b)", "Larger of two values.", 'maximum(col("x"), col("y"))'),
|
|
29
|
+
FormulaEntry("min", "Math", "min(a, b)", "Smaller of two values.", 'min(col("x"), col("y"))'),
|
|
30
|
+
FormulaEntry("max", "Math", "max(a, b)", "Larger of two values.", 'max(col("x"), col("y"))'),
|
|
31
|
+
FormulaEntry("sin", "Math", "sin(value)", "Sine in radians.", 'sin(col("x"))'),
|
|
32
|
+
FormulaEntry("cos", "Math", "cos(value)", "Cosine in radians.", 'cos(col("x"))'),
|
|
33
|
+
FormulaEntry("tan", "Math", "tan(value)", "Tangent in radians.", 'tan(col("x"))'),
|
|
34
|
+
FormulaEntry("mean", "Statistical", "mean(value)", "Mean of a column.", 'mean(col("x"))'),
|
|
35
|
+
FormulaEntry("median", "Statistical", "median(value)", "Median of a column.", 'median(col("x"))'),
|
|
36
|
+
FormulaEntry("std", "Statistical", "std(value)", "Sample standard deviation.", 'std(col("x"))'),
|
|
37
|
+
FormulaEntry("var", "Statistical", "var(value)", "Sample variance.", 'var(col("x"))'),
|
|
38
|
+
FormulaEntry("sum", "Statistical", "sum(value)", "Sum of a column.", 'sum(col("x"))'),
|
|
39
|
+
FormulaEntry("count", "Statistical", "count(value)", "Count of nonmissing values.", 'count(col("x"))'),
|
|
40
|
+
FormulaEntry("quantile", "Statistical", "quantile(value, q)", "Quantile from 0 to 1.", 'quantile(col("x"), 0.9)'),
|
|
41
|
+
FormulaEntry("zscore", "Statistical", "zscore(value)", "Standardize values using the column mean and standard deviation.", 'zscore(col("x"))'),
|
|
42
|
+
FormulaEntry("normalize", "Statistical", "normalize(value)", "Scale values to the range 0 to 1.", 'normalize(col("x"))'),
|
|
43
|
+
FormulaEntry("rank", "Statistical", "rank(value)", "Average rank of each value.", 'rank(col("x"))'),
|
|
44
|
+
FormulaEntry("where", "Conditional", "where(condition, when_true, when_false)", "Choose one of two values based on a condition.", 'where(col("x") > 0, "positive", "not positive")'),
|
|
45
|
+
FormulaEntry("ifelse", "Conditional", "ifelse(condition, when_true, when_false)", "Alias for where.", 'ifelse(col("x") > 0, 1, 0)'),
|
|
46
|
+
FormulaEntry("is_missing", "Missing", "is_missing(value)", "True when a value is missing.", 'is_missing(col("x"))'),
|
|
47
|
+
FormulaEntry("isnull", "Missing", "isnull(value)", "True when a value is missing.", 'isnull(col("x"))'),
|
|
48
|
+
FormulaEntry("notnull", "Missing", "notnull(value)", "True when a value is not missing.", 'notnull(col("x"))'),
|
|
49
|
+
FormulaEntry("notmissing", "Missing", "notmissing(value)", "True when a value is not missing.", 'notmissing(col("x"))'),
|
|
50
|
+
FormulaEntry("if_missing", "Missing", "if_missing(value, replacement)", "Replace missing values.", 'if_missing(col("x"), 0)'),
|
|
51
|
+
FormulaEntry("concat", "Text", "concat(text1, text2, ...)", "Join text values.", 'concat(col("first"), " ", col("last"))'),
|
|
52
|
+
FormulaEntry("lower", "Text", "lower(text)", "Convert text to lowercase.", 'lower(col("name"))'),
|
|
53
|
+
FormulaEntry("upper", "Text", "upper(text)", "Convert text to uppercase.", 'upper(col("name"))'),
|
|
54
|
+
FormulaEntry("strip", "Text", "strip(text)", "Remove leading and trailing spaces.", 'strip(col("name"))'),
|
|
55
|
+
FormulaEntry("contains", "Text", "contains(text, pattern, case=True, regex=False)", "Test whether text contains a pattern.", 'contains(col("name"), "inc", case=False)'),
|
|
56
|
+
FormulaEntry("startswith", "Text", "startswith(text, prefix, case=True)", "Test whether text starts with a prefix.", 'startswith(col("code"), "A")'),
|
|
57
|
+
FormulaEntry("endswith", "Text", "endswith(text, suffix, case=True)", "Test whether text ends with a suffix.", 'endswith(col("code"), "_01")'),
|
|
58
|
+
FormulaEntry("replace", "Text", "replace(text, old, new)", "Replace literal text.", 'replace(col("name"), "Inc", "LLC")'),
|
|
59
|
+
FormulaEntry("year", "Date and Time", "year(value)", "Extract the year.", 'year(col("date"))'),
|
|
60
|
+
FormulaEntry("month", "Date and Time", "month(value)", "Extract the month.", 'month(col("date"))'),
|
|
61
|
+
FormulaEntry("day", "Date and Time", "day(value)", "Extract the day of month.", 'day(col("date"))'),
|
|
62
|
+
FormulaEntry("today", "Date and Time", "today()", "Current date.", "today()"),
|
|
63
|
+
FormulaEntry("row", "Row and Table", "row()", "One-based row number.", "row()"),
|
|
64
|
+
FormulaEntry("col", "Row and Table", 'col("name")', "Reference a column.", 'col("x")'),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def entries_by_category(columns: list[str] | None = None) -> dict[str, list[FormulaEntry | tuple[str, str]]]:
|
|
69
|
+
grouped: dict[str, list[FormulaEntry | tuple[str, str]]] = {}
|
|
70
|
+
for entry in FORMULA_ENTRIES:
|
|
71
|
+
grouped.setdefault(entry.category, []).append(entry)
|
|
72
|
+
if columns:
|
|
73
|
+
grouped["Columns"] = [(column, f'col("{column}")') for column in columns]
|
|
74
|
+
return grouped
|