learnstat 0.1.0__tar.gz → 0.2.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.
- learnstat-0.2.0/LICENSE +21 -0
- {learnstat-0.1.0/learnstat.egg-info → learnstat-0.2.0}/PKG-INFO +43 -8
- learnstat-0.1.0/PKG-INFO → learnstat-0.2.0/README.md +169 -164
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/__init__.py +1 -1
- learnstat-0.2.0/learnstat/cli.py +338 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/commands.py +24 -1
- learnstat-0.2.0/learnstat/config.py +223 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/knowledge.py +1 -1
- learnstat-0.2.0/learnstat/llm.py +280 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/profile.py +1 -1
- learnstat-0.2.0/learnstat/providers.py +78 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/session.py +19 -12
- learnstat-0.2.0/learnstat/setup.py +308 -0
- learnstat-0.1.0/README.md → learnstat-0.2.0/learnstat.egg-info/PKG-INFO +199 -136
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat.egg-info/SOURCES.txt +5 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat.egg-info/requires.txt +0 -4
- {learnstat-0.1.0 → learnstat-0.2.0}/pyproject.toml +7 -3
- learnstat-0.2.0/tests/test_ai_config.py +258 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/tests/test_ipython.py +2 -1
- learnstat-0.1.0/learnstat/cli.py +0 -184
- learnstat-0.1.0/learnstat/llm.py +0 -204
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/advisor.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/ipython_ext.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/memory.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/recovery.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/safety.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat/suggestions.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat.egg-info/dependency_links.txt +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat.egg-info/entry_points.txt +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/learnstat.egg-info/top_level.txt +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/setup.cfg +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/tests/test_advisor.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/tests/test_commands.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/tests/test_profile_memory.py +0 -0
- {learnstat-0.1.0 → learnstat-0.2.0}/tests/test_recovery.py +0 -0
learnstat-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Umor Faruk Supto
|
|
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.
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: learnstat
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: An AI-assisted learning companion for statistical analysis with pandas, NumPy, SciPy and Matplotlib.
|
|
5
5
|
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/umorfaruksupto/leanstat
|
|
7
|
+
Project-URL: Repository, https://github.com/umorfaruksupto/leanstat
|
|
8
|
+
Project-URL: PyPI, https://pypi.org/project/learnstat/
|
|
6
9
|
Requires-Python: >=3.10
|
|
7
10
|
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
8
12
|
Requires-Dist: pandas>=2.0
|
|
9
13
|
Requires-Dist: numpy>=1.24
|
|
10
14
|
Provides-Extra: viz
|
|
11
15
|
Requires-Dist: matplotlib>=3.7; extra == "viz"
|
|
12
16
|
Provides-Extra: stats
|
|
13
17
|
Requires-Dist: scipy>=1.10; extra == "stats"
|
|
14
|
-
Provides-Extra: ai
|
|
15
|
-
Requires-Dist: anthropic>=1.0; extra == "ai"
|
|
16
18
|
Provides-Extra: jupyter
|
|
17
19
|
Requires-Dist: ipython>=8.0; extra == "jupyter"
|
|
18
20
|
Provides-Extra: all
|
|
19
21
|
Requires-Dist: matplotlib>=3.7; extra == "all"
|
|
20
22
|
Requires-Dist: scipy>=1.10; extra == "all"
|
|
21
|
-
Requires-Dist: anthropic>=1.0; extra == "all"
|
|
22
23
|
Requires-Dist: ipython>=8.0; extra == "all"
|
|
23
24
|
Provides-Extra: dev
|
|
24
25
|
Requires-Dist: pytest>=7; extra == "dev"
|
|
25
26
|
Requires-Dist: matplotlib>=3.7; extra == "dev"
|
|
26
27
|
Requires-Dist: scipy>=1.10; extra == "dev"
|
|
27
28
|
Requires-Dist: ipython>=8.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
28
30
|
|
|
29
31
|
# learnstat
|
|
30
32
|
|
|
@@ -40,14 +42,43 @@ You write ordinary **pandas / NumPy / SciPy / Matplotlib** code. learnstat:
|
|
|
40
42
|
|
|
41
43
|
It's not a new language. Everything you learn uses the real pandas, SciPy and Matplotlib APIs, so the skills carry over to the rest of the ecosystem.
|
|
42
44
|
|
|
45
|
+
[](https://pypi.org/project/learnstat/)
|
|
46
|
+
|
|
43
47
|
## Install
|
|
44
48
|
|
|
49
|
+
From PyPI: <https://pypi.org/project/learnstat/>
|
|
50
|
+
|
|
45
51
|
```bash
|
|
46
|
-
pip install
|
|
47
|
-
pip install -e .
|
|
52
|
+
pip install "learnstat[all]" # from PyPI
|
|
53
|
+
pip install -e ".[all]" # pandas, numpy, matplotlib, scipy, ipython
|
|
54
|
+
pip install -e . # core only: profiling, rules, recovery
|
|
48
55
|
```
|
|
49
56
|
|
|
50
|
-
|
|
57
|
+
### Add an AI (optional)
|
|
58
|
+
|
|
59
|
+
Just run `learnstat`. If no AI is set up yet it offers a guided setup, and you can repeat it any time with `learnstat setup` (or `/ai` inside a session):
|
|
60
|
+
|
|
61
|
+
1. **Choose the company**: OpenAI, Anthropic, Google Gemini, xAI, Mistral, DeepSeek, Groq, Together, OpenRouter, Ollama, LM Studio, or any other OpenAI-compatible endpoint.
|
|
62
|
+
2. **Paste your API key**. The input is hidden, and local servers such as Ollama need no key.
|
|
63
|
+
3. **Pick a model** from the list your key can actually use. Type part of a name to filter.
|
|
64
|
+
4. **learnstat checks it** with a live test request and shows `OK` or the exact problem (rejected key, unknown model, no connection, quota), with options to fix it.
|
|
65
|
+
5. It saves the account and starts the interactive session.
|
|
66
|
+
|
|
67
|
+
Several accounts can be saved and switched: run `learnstat setup` and pick a number, or use `/ai use <name>` in a session. The AI features need no extra package.
|
|
68
|
+
|
|
69
|
+
For scripts and CI there is a non-interactive route:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
learnstat config set api_key sk-your-key
|
|
73
|
+
learnstat config set base_url https://openrouter.ai/api/v1 # default: the active company's endpoint
|
|
74
|
+
learnstat config set model openai/gpt-4o-mini
|
|
75
|
+
learnstat config list # saved accounts learnstat config use <name> # switch
|
|
76
|
+
learnstat config test # one tiny request learnstat config show # key is masked
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Accounts are stored in `~/.learnstat/config.json` (`learnstat config path` prints the location), readable only by you where the OS allows it. The environment variables `LEARNSTAT_API_KEY`, `LEARNSTAT_BASE_URL` and `LEARNSTAT_MODEL` override the active account for one run.
|
|
80
|
+
|
|
81
|
+
With an AI configured, explanations are tailored to your dataset, `/review` checks code for issues the rules miss, and the AI can propose fixes for errors the rules can't handle. Without it, everything else still works offline. Pass `--no-ai` to switch it off for one run.
|
|
51
82
|
|
|
52
83
|
## Use it
|
|
53
84
|
|
|
@@ -85,6 +116,7 @@ learnstat check analysis.py # suggestions only, nothing is executed
|
|
|
85
116
|
learnstat watch analysis.py # re-checks every time you save the file
|
|
86
117
|
learnstat run analysis.py # runs with suggestions and guarded recovery
|
|
87
118
|
learnstat repl --data survey.csv # interactive, with /commands
|
|
119
|
+
learnstat config show # AI settings (see "Add an AI")
|
|
88
120
|
```
|
|
89
121
|
|
|
90
122
|
### Plain Python
|
|
@@ -141,7 +173,10 @@ learnstat/
|
|
|
141
173
|
knowledge.py offline explanations behind /describe, /alternatives, /learn
|
|
142
174
|
recovery.py error diagnosis, fix proposal, validation, bounded retry
|
|
143
175
|
safety.py detection of destructive side effects
|
|
144
|
-
llm.py optional
|
|
176
|
+
llm.py optional AI backend (OpenAI-compatible endpoint)
|
|
177
|
+
config.py saved AI accounts: provider, api_key, base_url, model
|
|
178
|
+
providers.py presets for the AI companies
|
|
179
|
+
setup.py guided terminal setup (company -> key -> model -> check)
|
|
145
180
|
session.py ties it together; read_csv/track/check/run
|
|
146
181
|
commands.py slash commands
|
|
147
182
|
ipython_ext.py %load_ext learnstat
|
|
@@ -1,164 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/
|
|
74
|
-
/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
learnstat
|
|
85
|
-
learnstat
|
|
86
|
-
learnstat
|
|
87
|
-
learnstat
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
|
109
|
-
|
|
110
|
-
| `/
|
|
111
|
-
| `/
|
|
112
|
-
| `/
|
|
113
|
-
| `/
|
|
114
|
-
| `/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
# learnstat
|
|
2
|
+
|
|
3
|
+
An AI-assisted learning companion for statistical analysis in Python.
|
|
4
|
+
|
|
5
|
+
You write ordinary **pandas / NumPy / SciPy / Matplotlib** code. learnstat:
|
|
6
|
+
|
|
7
|
+
1. **Understands your dataset.** It profiles the data once and keeps a Markdown memory file of it.
|
|
8
|
+
2. **Suggests better approaches as you write.** For example, it flags a pie chart of 12 categories and suggests a sorted bar chart, explaining why.
|
|
9
|
+
3. **Explains itself** through `/describe`, `/alternatives`, `/learn`, `/memory` and `/fix`.
|
|
10
|
+
4. **Recovers from mechanical errors.** It fixes typos in column names, methods and keywords, plus missing imports and unclosed brackets, and shows you every change.
|
|
11
|
+
5. **Leaves analytical decisions to you.** Data-quality and statistical-method problems are explained but never "fixed" automatically.
|
|
12
|
+
|
|
13
|
+
It's not a new language. Everything you learn uses the real pandas, SciPy and Matplotlib APIs, so the skills carry over to the rest of the ecosystem.
|
|
14
|
+
|
|
15
|
+
[](https://pypi.org/project/learnstat/)
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
From PyPI: <https://pypi.org/project/learnstat/>
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install "learnstat[all]" # from PyPI
|
|
23
|
+
pip install -e ".[all]" # pandas, numpy, matplotlib, scipy, ipython
|
|
24
|
+
pip install -e . # core only: profiling, rules, recovery
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Add an AI (optional)
|
|
28
|
+
|
|
29
|
+
Just run `learnstat`. If no AI is set up yet it offers a guided setup, and you can repeat it any time with `learnstat setup` (or `/ai` inside a session):
|
|
30
|
+
|
|
31
|
+
1. **Choose the company**: OpenAI, Anthropic, Google Gemini, xAI, Mistral, DeepSeek, Groq, Together, OpenRouter, Ollama, LM Studio, or any other OpenAI-compatible endpoint.
|
|
32
|
+
2. **Paste your API key**. The input is hidden, and local servers such as Ollama need no key.
|
|
33
|
+
3. **Pick a model** from the list your key can actually use. Type part of a name to filter.
|
|
34
|
+
4. **learnstat checks it** with a live test request and shows `OK` or the exact problem (rejected key, unknown model, no connection, quota), with options to fix it.
|
|
35
|
+
5. It saves the account and starts the interactive session.
|
|
36
|
+
|
|
37
|
+
Several accounts can be saved and switched: run `learnstat setup` and pick a number, or use `/ai use <name>` in a session. The AI features need no extra package.
|
|
38
|
+
|
|
39
|
+
For scripts and CI there is a non-interactive route:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
learnstat config set api_key sk-your-key
|
|
43
|
+
learnstat config set base_url https://openrouter.ai/api/v1 # default: the active company's endpoint
|
|
44
|
+
learnstat config set model openai/gpt-4o-mini
|
|
45
|
+
learnstat config list # saved accounts learnstat config use <name> # switch
|
|
46
|
+
learnstat config test # one tiny request learnstat config show # key is masked
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Accounts are stored in `~/.learnstat/config.json` (`learnstat config path` prints the location), readable only by you where the OS allows it. The environment variables `LEARNSTAT_API_KEY`, `LEARNSTAT_BASE_URL` and `LEARNSTAT_MODEL` override the active account for one run.
|
|
50
|
+
|
|
51
|
+
With an AI configured, explanations are tailored to your dataset, `/review` checks code for issues the rules miss, and the AI can propose fixes for errors the rules can't handle. Without it, everything else still works offline. Pass `--no-ai` to switch it off for one run.
|
|
52
|
+
|
|
53
|
+
## Use it
|
|
54
|
+
|
|
55
|
+
### Jupyter
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
%load_ext learnstat
|
|
59
|
+
import learnstat as ls
|
|
60
|
+
df = ls.read_csv("survey.csv") # a normal DataFrame, now profiled into .learnstat/survey.md
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
df["country"].value_counts().plot.pie()
|
|
65
|
+
# [!] Suggestion #1 (line 1): Pie chart with 12 categories
|
|
66
|
+
# Issue: `country` has 12 categories; slices this numerous are hard to compare by angle.
|
|
67
|
+
# Instead: A horizontal bar chart of the counts, sorted by size.
|
|
68
|
+
# Why: Bars share a common baseline ...
|
|
69
|
+
# How: counts = df['country'].value_counts() ...
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
/describe <- the concept, why it fits this data, when another method is better
|
|
74
|
+
/accept <- puts the suggested code in a NEW cell; your cell is untouched
|
|
75
|
+
/reject only 3 countries matter here <- recorded in memory, not suggested again
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
When a cell raises an error, learnstat diagnoses the failing statement. If it's a mechanical mistake, learnstat corrects it, re-runs only that statement and the ones after it, and prints the diff. A cell with a syntax error gets a corrected copy placed in the next cell for you to review.
|
|
79
|
+
|
|
80
|
+
### Command line
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
cd examples && python make_survey.py
|
|
84
|
+
learnstat profile survey.csv # writes .learnstat/survey.md and prints it
|
|
85
|
+
learnstat check analysis.py # suggestions only, nothing is executed
|
|
86
|
+
learnstat watch analysis.py # re-checks every time you save the file
|
|
87
|
+
learnstat run analysis.py # runs with suggestions and guarded recovery
|
|
88
|
+
learnstat repl --data survey.csv # interactive, with /commands
|
|
89
|
+
learnstat config show # AI settings (see "Add an AI")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Plain Python
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import learnstat as ls
|
|
96
|
+
df = ls.read_csv("survey.csv")
|
|
97
|
+
ls.check("df['income'].mean()") # suggestions without running
|
|
98
|
+
print(ls.command("/describe"))
|
|
99
|
+
|
|
100
|
+
s = ls.Session(confirm=lambda q: input(q + " [y/N] ") == "y")
|
|
101
|
+
s.ns["df"] = s.read_csv("survey.csv")
|
|
102
|
+
result = s.run("df.groupBy('group')['score'].median()")
|
|
103
|
+
print(result.final_code) # df.groupby(...)... your source is never modified
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
| Command | What it does |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `/describe [id]` | Explains the latest (or given) suggestion, or the latest error: the concept, the purpose of the function, why it fits this data, and when something else is better |
|
|
111
|
+
| `/alternatives [id]` | Other ways to reach the same goal, with trade-offs |
|
|
112
|
+
| `/learn [topic]` | A short lesson with an exercise on your own data |
|
|
113
|
+
| `/fix` | The last error diagnosis; in interactive mode, a retry of the failed statement |
|
|
114
|
+
| `/memory [show\|note\|decide\|refresh]` | View or update the dataset's persistent profile |
|
|
115
|
+
| `/accept [id]`, `/reject [id] [why]` | Accept or reject a suggestion; the decision is saved in memory |
|
|
116
|
+
| `/suggestions`, `/review`, `/ask`, `/status`, `/help` | |
|
|
117
|
+
|
|
118
|
+
## Dataset memory
|
|
119
|
+
|
|
120
|
+
`ls.read_csv` profiles the data and writes two files to `.learnstat/`:
|
|
121
|
+
|
|
122
|
+
- `survey.md`: columns, types, missing values, likely column meanings (marked as guesses), distributions, relationships, data-quality issues, suggested analyses, assumptions, **your analytical decisions** and notes.
|
|
123
|
+
- `survey.json`: the machine-readable cache. It includes a content fingerprint, so the data is only re-profiled when it actually changes. Decisions and notes carry over when that happens.
|
|
124
|
+
|
|
125
|
+
## How error recovery stays safe
|
|
126
|
+
|
|
127
|
+
- Code runs **one top-level statement at a time**. When statement *k* fails, only statement *k* is corrected and retried, so earlier side effects are never repeated.
|
|
128
|
+
- Errors are classified as **syntax, name, attribute, argument, column, data-quality, statistical-method, environment** or other runtime errors.
|
|
129
|
+
- Only mechanical mistakes are corrected automatically, and only to a unique, high-similarity match.
|
|
130
|
+
- Before a fix runs, it must compile. It must not introduce file, shell or network operations, must not change which variables are assigned, must not add data-altering calls (`dropna`, `fillna`, `astype` and so on), and must not change the statistical method.
|
|
131
|
+
- AI-proposed fixes always need your confirmation. So does retrying a loop or block, since that could repeat side effects.
|
|
132
|
+
- Retries are bounded (`max_attempts`, 3 by default). If the same error comes back, recovery stops and gives you a concrete next step.
|
|
133
|
+
- Code that deletes or overwrites files, runs shell commands or opens network connections only runs after you confirm.
|
|
134
|
+
- **This is a policy layer, not a sandbox.** Your code runs in your Python process with your permissions, exactly as if you had run it yourself.
|
|
135
|
+
|
|
136
|
+
## Project layout
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
learnstat/
|
|
140
|
+
profile.py dataset profiling (no AI)
|
|
141
|
+
memory.py Markdown + JSON dataset memory
|
|
142
|
+
advisor.py AST-based, data-aware suggestion rules
|
|
143
|
+
knowledge.py offline explanations behind /describe, /alternatives, /learn
|
|
144
|
+
recovery.py error diagnosis, fix proposal, validation, bounded retry
|
|
145
|
+
safety.py detection of destructive side effects
|
|
146
|
+
llm.py optional AI backend (OpenAI-compatible endpoint)
|
|
147
|
+
config.py saved AI accounts: provider, api_key, base_url, model
|
|
148
|
+
providers.py presets for the AI companies
|
|
149
|
+
setup.py guided terminal setup (company -> key -> model -> check)
|
|
150
|
+
session.py ties it together; read_csv/track/check/run
|
|
151
|
+
commands.py slash commands
|
|
152
|
+
ipython_ext.py %load_ext learnstat
|
|
153
|
+
cli.py learnstat profile|check|watch|run|repl
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Add a rule by writing a function `(call, resolver, code) -> Suggestion | None` in `advisor.py`, appending it to `RULES`, and adding its concept to `knowledge.py`.
|
|
157
|
+
|
|
158
|
+
## Roadmap
|
|
159
|
+
|
|
160
|
+
- A language-server (LSP) frontend for suggestions while typing in VS Code and JupyterLab. The advisor is already editor-agnostic.
|
|
161
|
+
- More rules: multiple-comparison corrections, chi-square expected counts, normality checks before parametric tests, time-series plotting.
|
|
162
|
+
- Learning-progress tracking, so advice fades as the user masters a concept.
|
|
163
|
+
|
|
164
|
+
## Tests
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pip install -e ".[dev]"
|
|
168
|
+
pytest
|
|
169
|
+
```
|