dataframe-toolkit 0.28.0__tar.gz → 0.30.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.
- dataframe_toolkit-0.28.0/README.md → dataframe_toolkit-0.30.0/PKG-INFO +56 -1
- dataframe_toolkit-0.28.0/PKG-INFO → dataframe_toolkit-0.30.0/README.md +25 -31
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/pyproject.toml +2 -1
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/pyproject.toml.orig +2 -1
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/cli.py +14 -4
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/__init__.py +1 -0
- dataframe_toolkit-0.30.0/src/dftk/commands/completion_cmd.py +158 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/line_cmd.py +3 -1
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/scat_cmd.py +9 -1
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/skill_cmd.py +6 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/io.py +107 -44
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/plot.py +81 -2
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/skills/dftk/SKILL.md +15 -3
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/__init__.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/annotate_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/append_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/base.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/binx_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/box_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/chi_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/clean_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/cleannames_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/concat_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/corr_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/dataset_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/describe_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/eval_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/explode_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/fit_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/forest_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/func_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/heatmap_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/help.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/hist_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/implode_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/info_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/interp_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/locus_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/manhattan_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/melt_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/merge_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/pairs_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/phewas_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/pivot_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/print_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/qq_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/query_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/randvar_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/sample_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/scale_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/segid_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/split_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/stat_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/test_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/transpose_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/commands/wstat_cmd.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/__init__.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/copula.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/docformats.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/evalfuncs.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/gwas.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/seed.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/seq.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/common/stats.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/io.py +0 -0
- {dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/skills/dftk/references/snakemake.md +0 -0
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: dataframe-toolkit
|
|
3
|
+
Version: 0.30.0
|
|
4
|
+
Summary: A command-line toolkit for DataFrame analysis and manipulation
|
|
5
|
+
Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
|
|
6
|
+
Author: Gunnar Pálsson
|
|
7
|
+
Author-email: Gunnar Pálsson <hemingur@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Dist: pandas>=2.1
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: pyarrow>=12.0
|
|
18
|
+
Requires-Dist: scipy>=1.10
|
|
19
|
+
Requires-Dist: statsmodels>=0.14
|
|
20
|
+
Requires-Dist: patsy>=0.5.6
|
|
21
|
+
Requires-Dist: duckdb>=0.8
|
|
22
|
+
Requires-Dist: matplotlib>=3.7
|
|
23
|
+
Requires-Dist: pillow>=13.0
|
|
24
|
+
Requires-Dist: seaborn>=0.12
|
|
25
|
+
Requires-Dist: tqdm>=4.65
|
|
26
|
+
Requires-Dist: shtab>=1.7
|
|
27
|
+
Requires-Python: >=3.12
|
|
28
|
+
Project-URL: Homepage, https://github.com/hemingur/dataframe-toolkit
|
|
29
|
+
Project-URL: Repository, https://github.com/hemingur/dataframe-toolkit
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
1
32
|
# dftk — DataFrame analysis and manipulation toolkit
|
|
2
33
|
|
|
3
34
|
`dftk` is a command-line toolkit for exploratory data analysis on TSV files.
|
|
@@ -69,6 +100,29 @@ It prints where it installed the skill. Run it again after upgrading dftk
|
|
|
69
100
|
so the skill matches the installed version; it replaces only the earlier
|
|
70
101
|
dftk skill. The source is in `src/dftk/skills/dftk/`.
|
|
71
102
|
|
|
103
|
+
### Tab completion
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
dftk completion install # for your shell ($SHELL): bash or zsh
|
|
107
|
+
dftk completion install --shell zsh
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Tab then completes commands, options, the values an option allows
|
|
111
|
+
(`--format`, `--fit`, `--catwidth`, …) and file names. The script is plain
|
|
112
|
+
shell generated from dftk's own parsers, so pressing Tab is instant.
|
|
113
|
+
|
|
114
|
+
- bash: installed to `~/.local/share/bash-completion/completions/dftk`, which
|
|
115
|
+
bash-completion loads by itself (most Linux systems load it in `~/.bashrc`;
|
|
116
|
+
on macOS, `brew install bash-completion@2`). Open a new shell.
|
|
117
|
+
- zsh: installed to `~/.zfunc/_dftk`. Add `fpath+=~/.zfunc` to `~/.zshrc`
|
|
118
|
+
before `compinit` (with Oh My Zsh, before the line that sources
|
|
119
|
+
`oh-my-zsh.sh`), then open a new shell; if it doesn't complete,
|
|
120
|
+
`rm ~/.zcompdump*` once.
|
|
121
|
+
|
|
122
|
+
Run it again after upgrading dftk so new options complete; `dftk skill install`
|
|
123
|
+
also refreshes an installed completion script. `dftk completion print`
|
|
124
|
+
writes the script to stdout instead.
|
|
125
|
+
|
|
72
126
|
## Quick example
|
|
73
127
|
|
|
74
128
|
```bash
|
|
@@ -144,7 +198,7 @@ publication-quality output.
|
|
|
144
198
|
| `locus` | Regional association plot: -log10(p) in one region coloured by r² with the lead variant (`--ldcol`), lead as a diamond, `--lead`/`--label` by ID or `chr:pos` |
|
|
145
199
|
| `manhattan` | Genome-wide -log10(p) by position (`Chr`, `pos`, `Pval`, or `--mlogpcol`/`--chi2col`); significance lines, thinning for millions of variants, `-g`/`--subgraphcol` for several scans |
|
|
146
200
|
|
|
147
|
-
`scat`, `line` and `hist` draw dashed reference lines with `--vline X` and `--hline Y`, each labelled when written `X:LABEL` (`--vline 412:carriers`); `forest` takes `--vline` and `box` `--hline`.
|
|
201
|
+
`scat`, `line` and `hist` draw dashed reference lines with `--vline X` and `--hline Y`, each labelled when written `X:LABEL` (`--vline 412:carriers`); `forest` takes `--vline` and `box` `--hline`. `scat` and `line` also draw sloped lines y = A + B*x with `--abline A:B[:LABEL]` (intercept, then slope, as in R; `--abline 0:0.15:15%`), across the whole panel without changing its limits; a bare `--abline` is the identity line y = x, and a negative intercept is written `--abline=-1:2`. On log axes the line is drawn as the curve it is. With `--subgraphcol` the same lines go on every panel.
|
|
148
202
|
|
|
149
203
|
### Utilities
|
|
150
204
|
|
|
@@ -156,6 +210,7 @@ publication-quality output.
|
|
|
156
210
|
| `annotate` | Read and write provenance metadata (genome, source, …) in parquet files |
|
|
157
211
|
| `print` | Read any dftk input (TSV, parquet, stdin) and write TSV, JSON, Markdown or LaTeX |
|
|
158
212
|
| `clean` | Remove leftover temp parquet pipe files from interrupted pipelines |
|
|
213
|
+
| `completion` | Tab completion for bash and zsh: `dftk completion install` |
|
|
159
214
|
| `help` | List all subcommands or show full help for one: `dftk help stat` |
|
|
160
215
|
|
|
161
216
|
## Common patterns
|
|
@@ -1,33 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: dataframe-toolkit
|
|
3
|
-
Version: 0.28.0
|
|
4
|
-
Summary: A command-line toolkit for DataFrame analysis and manipulation
|
|
5
|
-
Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
|
|
6
|
-
Author: Gunnar Pálsson
|
|
7
|
-
Author-email: Gunnar Pálsson <hemingur@gmail.com>
|
|
8
|
-
License: MIT
|
|
9
|
-
Classifier: Development Status :: 3 - Alpha
|
|
10
|
-
Classifier: Intended Audience :: Science/Research
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
13
|
-
Classifier: Topic :: Utilities
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Requires-Dist: pandas>=2.1
|
|
16
|
-
Requires-Dist: numpy>=1.24
|
|
17
|
-
Requires-Dist: pyarrow>=12.0
|
|
18
|
-
Requires-Dist: scipy>=1.10
|
|
19
|
-
Requires-Dist: statsmodels>=0.14
|
|
20
|
-
Requires-Dist: patsy>=0.5.6
|
|
21
|
-
Requires-Dist: duckdb>=0.8
|
|
22
|
-
Requires-Dist: matplotlib>=3.7
|
|
23
|
-
Requires-Dist: pillow>=13.0
|
|
24
|
-
Requires-Dist: seaborn>=0.12
|
|
25
|
-
Requires-Dist: tqdm>=4.65
|
|
26
|
-
Requires-Python: >=3.12
|
|
27
|
-
Project-URL: Homepage, https://github.com/hemingur/dataframe-toolkit
|
|
28
|
-
Project-URL: Repository, https://github.com/hemingur/dataframe-toolkit
|
|
29
|
-
Description-Content-Type: text/markdown
|
|
30
|
-
|
|
31
1
|
# dftk — DataFrame analysis and manipulation toolkit
|
|
32
2
|
|
|
33
3
|
`dftk` is a command-line toolkit for exploratory data analysis on TSV files.
|
|
@@ -99,6 +69,29 @@ It prints where it installed the skill. Run it again after upgrading dftk
|
|
|
99
69
|
so the skill matches the installed version; it replaces only the earlier
|
|
100
70
|
dftk skill. The source is in `src/dftk/skills/dftk/`.
|
|
101
71
|
|
|
72
|
+
### Tab completion
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
dftk completion install # for your shell ($SHELL): bash or zsh
|
|
76
|
+
dftk completion install --shell zsh
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Tab then completes commands, options, the values an option allows
|
|
80
|
+
(`--format`, `--fit`, `--catwidth`, …) and file names. The script is plain
|
|
81
|
+
shell generated from dftk's own parsers, so pressing Tab is instant.
|
|
82
|
+
|
|
83
|
+
- bash: installed to `~/.local/share/bash-completion/completions/dftk`, which
|
|
84
|
+
bash-completion loads by itself (most Linux systems load it in `~/.bashrc`;
|
|
85
|
+
on macOS, `brew install bash-completion@2`). Open a new shell.
|
|
86
|
+
- zsh: installed to `~/.zfunc/_dftk`. Add `fpath+=~/.zfunc` to `~/.zshrc`
|
|
87
|
+
before `compinit` (with Oh My Zsh, before the line that sources
|
|
88
|
+
`oh-my-zsh.sh`), then open a new shell; if it doesn't complete,
|
|
89
|
+
`rm ~/.zcompdump*` once.
|
|
90
|
+
|
|
91
|
+
Run it again after upgrading dftk so new options complete; `dftk skill install`
|
|
92
|
+
also refreshes an installed completion script. `dftk completion print`
|
|
93
|
+
writes the script to stdout instead.
|
|
94
|
+
|
|
102
95
|
## Quick example
|
|
103
96
|
|
|
104
97
|
```bash
|
|
@@ -174,7 +167,7 @@ publication-quality output.
|
|
|
174
167
|
| `locus` | Regional association plot: -log10(p) in one region coloured by r² with the lead variant (`--ldcol`), lead as a diamond, `--lead`/`--label` by ID or `chr:pos` |
|
|
175
168
|
| `manhattan` | Genome-wide -log10(p) by position (`Chr`, `pos`, `Pval`, or `--mlogpcol`/`--chi2col`); significance lines, thinning for millions of variants, `-g`/`--subgraphcol` for several scans |
|
|
176
169
|
|
|
177
|
-
`scat`, `line` and `hist` draw dashed reference lines with `--vline X` and `--hline Y`, each labelled when written `X:LABEL` (`--vline 412:carriers`); `forest` takes `--vline` and `box` `--hline`.
|
|
170
|
+
`scat`, `line` and `hist` draw dashed reference lines with `--vline X` and `--hline Y`, each labelled when written `X:LABEL` (`--vline 412:carriers`); `forest` takes `--vline` and `box` `--hline`. `scat` and `line` also draw sloped lines y = A + B*x with `--abline A:B[:LABEL]` (intercept, then slope, as in R; `--abline 0:0.15:15%`), across the whole panel without changing its limits; a bare `--abline` is the identity line y = x, and a negative intercept is written `--abline=-1:2`. On log axes the line is drawn as the curve it is. With `--subgraphcol` the same lines go on every panel.
|
|
178
171
|
|
|
179
172
|
### Utilities
|
|
180
173
|
|
|
@@ -186,6 +179,7 @@ publication-quality output.
|
|
|
186
179
|
| `annotate` | Read and write provenance metadata (genome, source, …) in parquet files |
|
|
187
180
|
| `print` | Read any dftk input (TSV, parquet, stdin) and write TSV, JSON, Markdown or LaTeX |
|
|
188
181
|
| `clean` | Remove leftover temp parquet pipe files from interrupted pipelines |
|
|
182
|
+
| `completion` | Tab completion for bash and zsh: `dftk completion install` |
|
|
189
183
|
| `help` | List all subcommands or show full help for one: `dftk help stat` |
|
|
190
184
|
|
|
191
185
|
## Common patterns
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dataframe-toolkit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.30.0"
|
|
4
4
|
description = "A command-line toolkit for DataFrame analysis and manipulation"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
keywords = [
|
|
@@ -32,6 +32,7 @@ dependencies = [
|
|
|
32
32
|
"pillow>=13.0",
|
|
33
33
|
"seaborn>=0.12",
|
|
34
34
|
"tqdm>=4.65",
|
|
35
|
+
"shtab>=1.7",
|
|
35
36
|
]
|
|
36
37
|
|
|
37
38
|
[[project.authors]]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dataframe-toolkit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.30.0"
|
|
4
4
|
description = "A command-line toolkit for DataFrame analysis and manipulation"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -29,6 +29,7 @@ dependencies = [
|
|
|
29
29
|
"pillow>=13.0", # not used directly (matplotlib needs it); floor for security fixes
|
|
30
30
|
"seaborn>=0.12",
|
|
31
31
|
"tqdm>=4.65",
|
|
32
|
+
"shtab>=1.7", # dftk completion: bash/zsh scripts from the parser
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
[project.urls]
|
|
@@ -35,11 +35,11 @@ def _commands_for(argv: list[str]) -> list[BaseCommand]:
|
|
|
35
35
|
return [load_command(argv[0])]
|
|
36
36
|
# `dftk --help`, no command, or an unknown name: load everything so the
|
|
37
37
|
# command listing and argparse's "invalid choice" message are complete.
|
|
38
|
-
|
|
39
|
-
return grouped + [load_command("help")]
|
|
38
|
+
return all_commands()
|
|
40
39
|
|
|
41
40
|
|
|
42
|
-
def
|
|
41
|
+
def build_parser(commands: list[BaseCommand]) -> argparse.ArgumentParser:
|
|
42
|
+
"""The dftk parser with a subparser for each of *commands*."""
|
|
43
43
|
parser = argparse.ArgumentParser(
|
|
44
44
|
prog="dftk",
|
|
45
45
|
description="DataFrame analysis and manipulation toolkit.",
|
|
@@ -59,11 +59,21 @@ def main() -> None:
|
|
|
59
59
|
subparsers = parser.add_subparsers(dest="command", metavar="COMMAND")
|
|
60
60
|
subparsers.required = True
|
|
61
61
|
|
|
62
|
-
for cmd in
|
|
62
|
+
for cmd in commands:
|
|
63
63
|
cmd_parser = subparsers.add_parser(cmd.name, help=cmd.help)
|
|
64
64
|
cmd.add_arguments(cmd_parser)
|
|
65
65
|
cmd_parser.set_defaults(command_instance=cmd)
|
|
66
|
+
return parser
|
|
66
67
|
|
|
68
|
+
|
|
69
|
+
def all_commands() -> list[BaseCommand]:
|
|
70
|
+
"""Every command, in the order `dftk --help` lists them."""
|
|
71
|
+
grouped = [cmd for _, cmds in load_command_groups() for cmd in cmds]
|
|
72
|
+
return grouped + [load_command("help")]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def main() -> None:
|
|
76
|
+
parser = build_parser(_commands_for(sys.argv[1:]))
|
|
67
77
|
args = parser.parse_args()
|
|
68
78
|
|
|
69
79
|
try:
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dftk.commands.completion_cmd — dftk completion subcommand.
|
|
3
|
+
|
|
4
|
+
Writes a Tab-completion script for bash or zsh, generated with shtab from the
|
|
5
|
+
real dftk parser: commands, options and their allowed values, and file names
|
|
6
|
+
where a command takes a file. The script is plain shell, so pressing Tab
|
|
7
|
+
never starts Python; it is regenerated after an upgrade.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import os
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from dftk.commands.base import BaseCommand
|
|
15
|
+
|
|
16
|
+
SHELLS = ("bash", "zsh")
|
|
17
|
+
|
|
18
|
+
_EPILOG = """\
|
|
19
|
+
Tab completes commands, options, the values an option allows (--format,
|
|
20
|
+
--fit, --catwidth, ...) and file names. Pressing Tab never starts Python:
|
|
21
|
+
the script lists everything, so it is instant.
|
|
22
|
+
|
|
23
|
+
dftk completion install install for your shell ($SHELL)
|
|
24
|
+
dftk completion install --shell zsh
|
|
25
|
+
dftk completion print > FILE write the script yourself
|
|
26
|
+
|
|
27
|
+
bash: installs to ~/.local/share/bash-completion/completions/dftk, which
|
|
28
|
+
bash-completion loads the first time you press Tab after "dftk" (Ubuntu
|
|
29
|
+
and most Linux systems load bash-completion in ~/.bashrc; on macOS install
|
|
30
|
+
it with Homebrew). Open a new shell to start using it.
|
|
31
|
+
|
|
32
|
+
zsh: installs to ~/.zfunc/_dftk. Add this to ~/.zshrc, before compinit or,
|
|
33
|
+
with Oh My Zsh, before the line that sources oh-my-zsh.sh:
|
|
34
|
+
|
|
35
|
+
fpath+=~/.zfunc
|
|
36
|
+
|
|
37
|
+
then open a new shell (if it does not complete, rm ~/.zcompdump* once).
|
|
38
|
+
|
|
39
|
+
Run "dftk completion install" again after upgrading dftk, so new commands
|
|
40
|
+
and options complete; "dftk skill install" also refreshes an installed
|
|
41
|
+
completion script.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def default_shell() -> str:
|
|
46
|
+
"""The user's shell from $SHELL, if dftk supports it, else bash."""
|
|
47
|
+
shell = Path(os.environ.get("SHELL", "")).name
|
|
48
|
+
return shell if shell in SHELLS else "bash"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def install_path(shell: str) -> Path:
|
|
52
|
+
"""Where `dftk completion install` puts the script for *shell*."""
|
|
53
|
+
home = Path.home()
|
|
54
|
+
if shell == "zsh":
|
|
55
|
+
return home / ".zfunc" / "_dftk"
|
|
56
|
+
user_dir = os.environ.get("BASH_COMPLETION_USER_DIR")
|
|
57
|
+
if user_dir:
|
|
58
|
+
return Path(user_dir) / "completions" / "dftk"
|
|
59
|
+
data = os.environ.get("XDG_DATA_HOME") or str(home / ".local" / "share")
|
|
60
|
+
return Path(data) / "bash-completion" / "completions" / "dftk"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _subparsers(parser: argparse.ArgumentParser) -> dict:
|
|
64
|
+
for action in parser._actions:
|
|
65
|
+
if isinstance(action, argparse._SubParsersAction):
|
|
66
|
+
return action.choices
|
|
67
|
+
return {}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _mark_completions(parser: argparse.ArgumentParser) -> None:
|
|
71
|
+
"""Tell shtab which arguments are files or directories, and complete
|
|
72
|
+
`dftk help COMMAND` with the command names."""
|
|
73
|
+
import shtab
|
|
74
|
+
|
|
75
|
+
commands = _subparsers(parser)
|
|
76
|
+
for name, sub in commands.items():
|
|
77
|
+
for action in sub._actions:
|
|
78
|
+
if action.nargs == 0 or action.choices:
|
|
79
|
+
continue
|
|
80
|
+
metavar = str(action.metavar or "")
|
|
81
|
+
if name == "help" and not action.option_strings:
|
|
82
|
+
action.choices = sorted(commands)
|
|
83
|
+
elif not action.option_strings and action.dest in (
|
|
84
|
+
"DATAFILE",
|
|
85
|
+
"DATAFILES",
|
|
86
|
+
"PARQUET",
|
|
87
|
+
):
|
|
88
|
+
action.complete = shtab.FILE
|
|
89
|
+
elif metavar in ("FILE", "PATH"):
|
|
90
|
+
action.complete = shtab.FILE
|
|
91
|
+
elif metavar == "DIR":
|
|
92
|
+
action.complete = shtab.DIRECTORY
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def completion_script(shell: str) -> str:
|
|
96
|
+
"""The completion script for *shell*, from every dftk command's parser."""
|
|
97
|
+
import shtab
|
|
98
|
+
|
|
99
|
+
from dftk.cli import all_commands, build_parser
|
|
100
|
+
|
|
101
|
+
parser = build_parser(all_commands())
|
|
102
|
+
_mark_completions(parser)
|
|
103
|
+
return shtab.complete(parser, shell=shell)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def install(shell: str) -> Path:
|
|
107
|
+
path = install_path(shell)
|
|
108
|
+
script = completion_script(shell)
|
|
109
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
path.write_text(script)
|
|
111
|
+
return path
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def refresh_installed() -> list[Path]:
|
|
115
|
+
"""Rewrite the completion scripts already installed (after an upgrade)."""
|
|
116
|
+
return [install(shell) for shell in SHELLS if install_path(shell).is_file()]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class CompletionCommand(BaseCommand):
|
|
120
|
+
@property
|
|
121
|
+
def name(self) -> str:
|
|
122
|
+
return "completion"
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def help(self) -> str:
|
|
126
|
+
return "Tab completion for bash and zsh"
|
|
127
|
+
|
|
128
|
+
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
129
|
+
parser.formatter_class = argparse.RawDescriptionHelpFormatter
|
|
130
|
+
parser.epilog = _EPILOG
|
|
131
|
+
parser.add_argument(
|
|
132
|
+
"action",
|
|
133
|
+
choices=["install", "print"],
|
|
134
|
+
help="install: write the script where the shell finds it; "
|
|
135
|
+
"print: write it to stdout.",
|
|
136
|
+
)
|
|
137
|
+
parser.add_argument(
|
|
138
|
+
"--shell",
|
|
139
|
+
choices=SHELLS,
|
|
140
|
+
default=None,
|
|
141
|
+
help="Shell to complete in (default: from $SHELL, else bash).",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
145
|
+
shell = args.shell or default_shell()
|
|
146
|
+
if args.action == "print":
|
|
147
|
+
print(completion_script(shell), end="")
|
|
148
|
+
return
|
|
149
|
+
path = install(shell)
|
|
150
|
+
print(f"Installed {shell} completion for dftk in {path}")
|
|
151
|
+
if shell == "zsh":
|
|
152
|
+
print(
|
|
153
|
+
"Add 'fpath+=~/.zfunc' to ~/.zshrc before compinit (with Oh My "
|
|
154
|
+
"Zsh: before it sources oh-my-zsh.sh), then open a new shell."
|
|
155
|
+
)
|
|
156
|
+
else:
|
|
157
|
+
print("Open a new shell to use it.")
|
|
158
|
+
print('Run "dftk completion install" again after upgrading dftk.')
|
|
@@ -27,6 +27,7 @@ from dftk.common.plot import (
|
|
|
27
27
|
add_legend_arguments,
|
|
28
28
|
add_refline_arguments,
|
|
29
29
|
add_xy_arguments,
|
|
30
|
+
apply_ablines,
|
|
30
31
|
apply_labels,
|
|
31
32
|
apply_limits,
|
|
32
33
|
apply_reflines,
|
|
@@ -166,6 +167,7 @@ def _line_ax(ax, df, args, title_suffix: str = ""):
|
|
|
166
167
|
|
|
167
168
|
apply_reflines(ax, args)
|
|
168
169
|
apply_limits(ax, args)
|
|
170
|
+
apply_ablines(ax, args)
|
|
169
171
|
apply_ticks(ax, args)
|
|
170
172
|
apply_labels(ax, args, default_xlabel=xcol or "", default_ylabel=ycol or "")
|
|
171
173
|
if title_suffix:
|
|
@@ -255,7 +257,7 @@ class LineCommand(BaseCommand):
|
|
|
255
257
|
self.add_read_arguments(parser)
|
|
256
258
|
add_xy_arguments(parser)
|
|
257
259
|
add_figure_arguments(parser)
|
|
258
|
-
add_refline_arguments(parser)
|
|
260
|
+
add_refline_arguments(parser, sloped=True)
|
|
259
261
|
add_group_arguments(parser)
|
|
260
262
|
add_legend_arguments(parser)
|
|
261
263
|
|
|
@@ -32,6 +32,7 @@ from dftk.common.plot import (
|
|
|
32
32
|
add_legend_arguments,
|
|
33
33
|
add_refline_arguments,
|
|
34
34
|
add_xy_arguments,
|
|
35
|
+
apply_ablines,
|
|
35
36
|
apply_labels,
|
|
36
37
|
apply_limits,
|
|
37
38
|
apply_reflines,
|
|
@@ -283,6 +284,7 @@ def _scatter_ax(ax, df, args, title_suffix: str = ""):
|
|
|
283
284
|
|
|
284
285
|
apply_reflines(ax, args)
|
|
285
286
|
apply_limits(ax, args)
|
|
287
|
+
apply_ablines(ax, args)
|
|
286
288
|
apply_ticks(ax, args)
|
|
287
289
|
apply_labels(ax, args, default_xlabel=xcol or "", default_ylabel=ycol or "")
|
|
288
290
|
if title_suffix:
|
|
@@ -324,6 +326,12 @@ can overshoot the data; a larger --frac or --xlim helps:
|
|
|
324
326
|
|
|
325
327
|
dftk dataset tips -o | dftk scat -x total_bill -y tip --fit lowess
|
|
326
328
|
|
|
329
|
+
Lines y = A + B*x, here 15 % and 20 % tips, on every panel (bare --abline
|
|
330
|
+
is y = x; a negative intercept is written --abline=-1:2):
|
|
331
|
+
|
|
332
|
+
dftk dataset tips -o | dftk scat -x total_bill -y tip --subgraphcol time \\
|
|
333
|
+
--abline 0:0.15:15% 0:0.2:20%
|
|
334
|
+
|
|
327
335
|
Hexagonal binning for large tables (54,000 diamonds), log colour scale and
|
|
328
336
|
log axes; hexagons are binned on the log scale:
|
|
329
337
|
|
|
@@ -386,7 +394,7 @@ class ScatCommand(BaseCommand):
|
|
|
386
394
|
self.add_read_arguments(parser)
|
|
387
395
|
add_xy_arguments(parser)
|
|
388
396
|
add_figure_arguments(parser)
|
|
389
|
-
add_refline_arguments(parser)
|
|
397
|
+
add_refline_arguments(parser, sloped=True)
|
|
390
398
|
add_group_arguments(parser)
|
|
391
399
|
add_legend_arguments(parser)
|
|
392
400
|
|
|
@@ -102,6 +102,12 @@ def _skill(args: argparse.Namespace) -> None:
|
|
|
102
102
|
replaced = _install(folder)
|
|
103
103
|
verb = "Updated" if replaced else "Installed"
|
|
104
104
|
print(f"{verb} the dftk skill (dftk {_dftk_version()}) in {folder / 'dftk'}")
|
|
105
|
+
# an installed Tab-completion script is refreshed too, so one command
|
|
106
|
+
# after an upgrade brings both up to date
|
|
107
|
+
from dftk.commands.completion_cmd import refresh_installed
|
|
108
|
+
|
|
109
|
+
for path in refresh_installed():
|
|
110
|
+
print(f"Updated the dftk completion script in {path}")
|
|
105
111
|
print('Run "dftk skill install" again after upgrading dftk.')
|
|
106
112
|
|
|
107
113
|
|
|
@@ -66,8 +66,93 @@ _CAST_TYPES: dict[str, object] = {
|
|
|
66
66
|
"bool": "bool",
|
|
67
67
|
"datetime64": "datetime64[ns]",
|
|
68
68
|
"category": "category",
|
|
69
|
+
"str": "string",
|
|
70
|
+
"string": "string",
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
|
|
74
|
+
def _query(df: pd.DataFrame, query: str, option: str) -> pd.DataFrame:
|
|
75
|
+
"""df.query for --prequery / --postquery; a bad expression is an input
|
|
76
|
+
error (pandas raises UndefinedVariableError, SyntaxError, ...)."""
|
|
77
|
+
try:
|
|
78
|
+
return df.query(query)
|
|
79
|
+
except Exception as exc:
|
|
80
|
+
raise ValueError(f"{option} {query!r}: {exc}") from None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _round(df: pd.DataFrame, item: str) -> pd.DataFrame:
|
|
84
|
+
"""Apply one --round COL:N (a glob rounds the numeric columns it matches)
|
|
85
|
+
or --round N (every float column). A malformed item, a literal column that
|
|
86
|
+
matches nothing or isn't numeric is an input error."""
|
|
87
|
+
col, sep, n = item.rpartition(":")
|
|
88
|
+
try:
|
|
89
|
+
ndigits = int(n)
|
|
90
|
+
except ValueError:
|
|
91
|
+
raise ValueError(f"--round expects COL:N or N, got {item!r}") from None
|
|
92
|
+
if not sep:
|
|
93
|
+
columns = [c for c in df.columns if df[c].dtype == np.float64]
|
|
94
|
+
elif not col:
|
|
95
|
+
raise ValueError(f"--round expects COL:N or N, got {item!r}")
|
|
96
|
+
elif frozenset("*?[") & set(col):
|
|
97
|
+
columns = [
|
|
98
|
+
c
|
|
99
|
+
for c in fnmatch.filter(df.columns, col)
|
|
100
|
+
if pd.api.types.is_numeric_dtype(df[c])
|
|
101
|
+
and not pd.api.types.is_bool_dtype(df[c])
|
|
102
|
+
]
|
|
103
|
+
elif col not in df.columns:
|
|
104
|
+
raise ValueError(
|
|
105
|
+
f"--round {item!r}: no column {col!r} (available: {list(df.columns)})"
|
|
106
|
+
)
|
|
107
|
+
elif not pd.api.types.is_numeric_dtype(df[col]):
|
|
108
|
+
raise ValueError(f"--round {item!r}: {col} is not numeric ({df[col].dtype})")
|
|
109
|
+
else:
|
|
110
|
+
columns = [col]
|
|
111
|
+
for c in columns:
|
|
112
|
+
df[c] = df[c].round(ndigits)
|
|
113
|
+
return df
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _cast(df: pd.DataFrame, item: str) -> pd.DataFrame:
|
|
117
|
+
"""Apply one --cast COL:TYPE. An unknown type, a literal column name that
|
|
118
|
+
matches nothing or a failed conversion is an input error."""
|
|
119
|
+
col, sep, coltype = item.rpartition(":")
|
|
120
|
+
if not sep or not col or not coltype:
|
|
121
|
+
raise ValueError(f"--cast expects COL:TYPE, got {item!r}")
|
|
122
|
+
# Case-sensitive: "int" is int64, "Int" is the nullable Int64
|
|
123
|
+
matches = [t for t in _CAST_TYPES if fnmatch.fnmatchcase(t, f"{coltype}*")]
|
|
124
|
+
if not matches:
|
|
125
|
+
raise ValueError(
|
|
126
|
+
f"--cast {item!r}: unknown type {coltype!r} "
|
|
127
|
+
f"(choose from {', '.join(_CAST_TYPES)})"
|
|
128
|
+
)
|
|
129
|
+
dtype = _CAST_TYPES[matches[0]]
|
|
130
|
+
columns = fnmatch.filter(df.columns, col)
|
|
131
|
+
if dtype in ("int64", "Int64"):
|
|
132
|
+
for c in columns:
|
|
133
|
+
if pd.api.types.is_float_dtype(df[c]):
|
|
134
|
+
values = df[c].dropna()
|
|
135
|
+
broken = values[values % 1 != 0]
|
|
136
|
+
if len(broken):
|
|
137
|
+
raise ValueError(
|
|
138
|
+
f"--cast {c}:{coltype}: {c} has non-whole numbers "
|
|
139
|
+
f"(e.g. {broken.iloc[0]}); use --round {c}:0 first"
|
|
140
|
+
)
|
|
141
|
+
if not columns and not (frozenset("*?[") & set(col)):
|
|
142
|
+
raise ValueError(
|
|
143
|
+
f"--cast {item!r}: no column {col!r} (available: {list(df.columns)})"
|
|
144
|
+
)
|
|
145
|
+
for c in columns:
|
|
146
|
+
try:
|
|
147
|
+
df[c] = df[c].astype(dtype)
|
|
148
|
+
except Exception as exc:
|
|
149
|
+
try: # e.g. "1.0" text to int: via float
|
|
150
|
+
df[c] = df[c].astype(float).astype(dtype)
|
|
151
|
+
except Exception:
|
|
152
|
+
raise ValueError(f"--cast {c}:{coltype}: {exc}") from None
|
|
153
|
+
return df
|
|
154
|
+
|
|
155
|
+
|
|
71
156
|
DFTK_TMPDIR: str = os.environ.get(
|
|
72
157
|
"DFTK_TMPDIR",
|
|
73
158
|
os.path.join(tempfile.gettempdir(), "dftk"),
|
|
@@ -544,11 +629,7 @@ class io:
|
|
|
544
629
|
# -- prequery ------------------------------------------------------
|
|
545
630
|
|
|
546
631
|
for query in prequery:
|
|
547
|
-
|
|
548
|
-
df = df.query(query)
|
|
549
|
-
except Exception as exc:
|
|
550
|
-
logging.error(f"--prequery failed ({query!r}): {exc}")
|
|
551
|
-
raise
|
|
632
|
+
df = _query(df, query, "--prequery")
|
|
552
633
|
|
|
553
634
|
return df
|
|
554
635
|
|
|
@@ -640,9 +721,12 @@ class io:
|
|
|
640
721
|
"--cast",
|
|
641
722
|
help=(
|
|
642
723
|
"Cast column to dtype (COL:TYPE). TYPE is one of object, int64, "
|
|
643
|
-
"Int64, float64, bool, datetime64, category (a prefix is
|
|
644
|
-
"e.g. int, Int, cat). Int64 is an integer column that
|
|
645
|
-
"empty cells
|
|
724
|
+
"Int64, float64, bool, datetime64, category, str (a prefix is "
|
|
725
|
+
"enough, e.g. int, Int, cat). Int64 is an integer column that "
|
|
726
|
+
"allows empty cells; str is text (written to parquet as a "
|
|
727
|
+
"string column; empty cells stay empty). Casts apply in "
|
|
728
|
+
"order, so --cast c:Int64 c:str turns 1.0 into 1. Glob "
|
|
729
|
+
"patterns supported; a type that doesn't fit is an error."
|
|
646
730
|
),
|
|
647
731
|
nargs="*",
|
|
648
732
|
default=None,
|
|
@@ -651,8 +735,11 @@ class io:
|
|
|
651
735
|
g.add_argument(
|
|
652
736
|
"--round",
|
|
653
737
|
help=(
|
|
654
|
-
"Round columns to N decimal places (COL:N
|
|
655
|
-
"A bare integer N rounds all
|
|
738
|
+
"Round columns to N decimal places (COL:N; a glob rounds "
|
|
739
|
+
"the numeric columns it matches). A bare integer N rounds all "
|
|
740
|
+
"float columns. Done before --cast, so --round x:0 --cast "
|
|
741
|
+
"x:int gives the nearest integer (halves go to the even "
|
|
742
|
+
"number: 2.5 to 2, 3.5 to 4)."
|
|
656
743
|
),
|
|
657
744
|
nargs="*",
|
|
658
745
|
default=None,
|
|
@@ -735,7 +822,9 @@ class io:
|
|
|
735
822
|
help=(
|
|
736
823
|
"Drop rows containing any NA value from the output. Applied "
|
|
737
824
|
"after the command has run, so it does not change what the "
|
|
738
|
-
"command sees (use --prequery for that)."
|
|
825
|
+
"command sees (use --prequery for that). For one column: "
|
|
826
|
+
"--postquery 'COL.notna()'; for 2 or missing: --postquery "
|
|
827
|
+
"'b == 2 or b.isna()' (b == 2 alone drops the missing rows)."
|
|
739
828
|
),
|
|
740
829
|
action="store_true",
|
|
741
830
|
)
|
|
@@ -789,27 +878,16 @@ class io:
|
|
|
789
878
|
|
|
790
879
|
# Post-query filter
|
|
791
880
|
for query in getattr(args, "postquery", []):
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
881
|
+
df = _query(df, query, "--postquery")
|
|
882
|
+
|
|
883
|
+
# Round decimal places; before --cast, so --round x:0 --cast x:int
|
|
884
|
+
# gives the nearest integer
|
|
885
|
+
for item in getattr(args, "round", None) or []:
|
|
886
|
+
df = _round(df, item)
|
|
797
887
|
|
|
798
888
|
# Cast columns
|
|
799
889
|
for item in getattr(args, "cast", None) or []:
|
|
800
|
-
|
|
801
|
-
col, coltype = item.split(":")
|
|
802
|
-
# Case-sensitive: "int" is int64, "Int" is the nullable Int64
|
|
803
|
-
pattern = f"{coltype}*"
|
|
804
|
-
matches = [t for t in _CAST_TYPES if fnmatch.fnmatchcase(t, pattern)]
|
|
805
|
-
dtype = _CAST_TYPES[matches[0]]
|
|
806
|
-
for c in fnmatch.filter(df.columns, col):
|
|
807
|
-
try:
|
|
808
|
-
df[c] = df[c].astype(dtype)
|
|
809
|
-
except Exception:
|
|
810
|
-
df[c] = df[c].astype(float).astype(dtype)
|
|
811
|
-
except Exception:
|
|
812
|
-
logging.warning(f"--cast: failed for {item!r}")
|
|
890
|
+
df = _cast(df, item)
|
|
813
891
|
|
|
814
892
|
# Sort; --sortasc or --sortdesc without names sorts by every column,
|
|
815
893
|
# left to right
|
|
@@ -888,21 +966,6 @@ class io:
|
|
|
888
966
|
except Exception as exc:
|
|
889
967
|
logging.error(f"--select failed: {exc}")
|
|
890
968
|
|
|
891
|
-
# Round decimal places
|
|
892
|
-
for item in getattr(args, "round", None) or []:
|
|
893
|
-
try:
|
|
894
|
-
col, n = item.split(":")
|
|
895
|
-
for c in fnmatch.filter(df.columns, col):
|
|
896
|
-
df[c] = df[c].round(int(n))
|
|
897
|
-
except Exception:
|
|
898
|
-
try:
|
|
899
|
-
n = int(item)
|
|
900
|
-
for c in df.columns:
|
|
901
|
-
if df[c].dtype == np.float64:
|
|
902
|
-
df[c] = df[c].round(n)
|
|
903
|
-
except Exception:
|
|
904
|
-
pass
|
|
905
|
-
|
|
906
969
|
# Deduplicate
|
|
907
970
|
dedup = getattr(args, "deduplicate", None)
|
|
908
971
|
if dedup is not None:
|
|
@@ -418,11 +418,90 @@ def apply_reflines(ax: matplotlib.axes.Axes, args: argparse.Namespace) -> None:
|
|
|
418
418
|
)
|
|
419
419
|
|
|
420
420
|
|
|
421
|
+
def abline(value: str) -> tuple[float, float, str | None]:
|
|
422
|
+
"""--abline value: INTERCEPT:SLOPE, or INTERCEPT:SLOPE:LABEL."""
|
|
423
|
+
a, sep, rest = value.partition(":")
|
|
424
|
+
b, _, label = rest.partition(":")
|
|
425
|
+
try:
|
|
426
|
+
if not sep:
|
|
427
|
+
raise ValueError
|
|
428
|
+
return float(a), float(b), (label or None)
|
|
429
|
+
except ValueError:
|
|
430
|
+
raise argparse.ArgumentTypeError(
|
|
431
|
+
f"expected INTERCEPT:SLOPE[:LABEL], not {value!r}"
|
|
432
|
+
) from None
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
class _AblineAction(argparse.Action):
|
|
436
|
+
"""--abline may be given more than once (a negative intercept needs
|
|
437
|
+
--abline=-1:2, one line per option); bare --abline adds y = x."""
|
|
438
|
+
|
|
439
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
440
|
+
lines = list(getattr(namespace, self.dest, None) or [])
|
|
441
|
+
lines += values or [(0.0, 1.0, None)]
|
|
442
|
+
setattr(namespace, self.dest, lines)
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def apply_ablines(ax: matplotlib.axes.Axes, args: argparse.Namespace) -> None:
|
|
446
|
+
"""Draw --abline lines y = a + b*x across the whole panel, in the style of
|
|
447
|
+
--vline / --hline. Call after apply_limits: the line is drawn over the
|
|
448
|
+
final x range and leaves the limits as they are, so it never zooms the
|
|
449
|
+
plot out. On a log axis the line is a curve, drawn point by point."""
|
|
450
|
+
lines = getattr(args, "abline", None)
|
|
451
|
+
if not lines:
|
|
452
|
+
return
|
|
453
|
+
import numpy as np
|
|
454
|
+
|
|
455
|
+
xlim, ylim = ax.get_xlim(), ax.get_ylim()
|
|
456
|
+
logx = ax.get_xscale() == "log"
|
|
457
|
+
x = np.geomspace(*xlim, 512) if logx else np.linspace(*xlim, 512)
|
|
458
|
+
lo, hi = sorted(ylim)
|
|
459
|
+
for a, b, label in lines:
|
|
460
|
+
y = a + b * x
|
|
461
|
+
ax.plot(x, y, color=_REFLINE_COLOUR, ls="--", lw=0.9, zorder=1.5)
|
|
462
|
+
if label:
|
|
463
|
+
# at the right-most point inside the panel, along the line
|
|
464
|
+
inside = np.flatnonzero((y > lo) & (y < hi))
|
|
465
|
+
if len(inside):
|
|
466
|
+
i = max(inside[0], inside[-1] - 10)
|
|
467
|
+
ax.text(
|
|
468
|
+
x[i],
|
|
469
|
+
y[i],
|
|
470
|
+
f"{label} ",
|
|
471
|
+
ha="right",
|
|
472
|
+
va="bottom",
|
|
473
|
+
fontsize="small",
|
|
474
|
+
color=_REFLINE_COLOUR,
|
|
475
|
+
rotation=float(np.degrees(np.arctan(b))),
|
|
476
|
+
rotation_mode="anchor",
|
|
477
|
+
transform_rotates_text=True,
|
|
478
|
+
)
|
|
479
|
+
ax.set_xlim(xlim)
|
|
480
|
+
ax.set_ylim(ylim)
|
|
481
|
+
|
|
482
|
+
|
|
421
483
|
def add_refline_arguments(
|
|
422
|
-
parser: argparse.ArgumentParser,
|
|
484
|
+
parser: argparse.ArgumentParser,
|
|
485
|
+
vertical: bool = True,
|
|
486
|
+
horizontal: bool = True,
|
|
487
|
+
sloped: bool = False,
|
|
423
488
|
) -> None:
|
|
424
|
-
"""Add --vline / --hline (reference lines with optional labels)
|
|
489
|
+
"""Add --vline / --hline (reference lines with optional labels), and
|
|
490
|
+
--abline with *sloped* (plots with a numeric x and y: scat, line)."""
|
|
425
491
|
g = parser.add_argument_group("reference lines")
|
|
492
|
+
if sloped:
|
|
493
|
+
g.add_argument(
|
|
494
|
+
"--abline",
|
|
495
|
+
nargs="*",
|
|
496
|
+
type=abline,
|
|
497
|
+
action=_AblineAction,
|
|
498
|
+
default=None,
|
|
499
|
+
metavar="A:B[:LABEL]",
|
|
500
|
+
help="Dashed line(s) y = A + B*x (intercept, then slope, as in "
|
|
501
|
+
"R's abline), across the whole panel, labelled if :LABEL is "
|
|
502
|
+
"given. Bare --abline is the identity line y = x (0:1). A "
|
|
503
|
+
"negative intercept needs =: --abline=-1:2. Repeatable.",
|
|
504
|
+
)
|
|
426
505
|
if vertical:
|
|
427
506
|
g.add_argument(
|
|
428
507
|
"--vline",
|
|
@@ -57,7 +57,8 @@ using a command for the first time.
|
|
|
57
57
|
`cleannames`, which also fixes headers such as `Sample ID` or `GC %`:
|
|
58
58
|
`dftk cleannames data.tsv --backend duckdb -o data.parquet`. Parquet keeps
|
|
59
59
|
the types, so later steps need no option.
|
|
60
|
-
For a column that is already float, `--cast COL:Int64` turns it back
|
|
60
|
+
For a column that is already float, `--cast COL:Int64` turns it back;
|
|
61
|
+
`--cast COL:str` makes numbers text (e.g. cluster numbers as categories).
|
|
61
62
|
`--digits N` writes such columns in exponent form (`2.49e+08`) and warns.
|
|
62
63
|
|
|
63
64
|
## Output modes (`-o`, on every data command)
|
|
@@ -88,6 +89,14 @@ right; give the file before them) / `--sort COL:a COL:d`,
|
|
|
88
89
|
`--dropna`, `--na_rep VAL`, `--removeheader`, and
|
|
89
90
|
`--meta KEY=VALUE` (provenance, see below).
|
|
90
91
|
|
|
92
|
+
Missing values in one column: `--dropna` drops rows with a gap in any column;
|
|
93
|
+
for one column filter instead, `--prequery 'a.notna()'` (before the command
|
|
94
|
+
runs) or `--postquery 'a.notna()'` (on the output). "2 or missing" is
|
|
95
|
+
`'b == 2 or b.isna()'`, or in SQL `b = 2 OR b IS NULL`: a comparison with a
|
|
96
|
+
missing value is false. Inequality differs: in a pandas expression `b != 3`
|
|
97
|
+
keeps the missing rows, in SQL `b <> 3` drops them. With `--backend duckdb`
|
|
98
|
+
only empty cells are missing; a column holding the text `NA` is read as text.
|
|
99
|
+
|
|
91
100
|
Output format: TSV unless `-o FILE` ends in `.json` (array of records),
|
|
92
101
|
`.jsonl`, `.md` (Markdown table) or `.tex` (bare booktabs tabular, for
|
|
93
102
|
`\input` in a LaTeX table); `--format tsv|json|jsonl|md|tex` does the same
|
|
@@ -175,11 +184,14 @@ Bonferroni per panel),
|
|
|
175
184
|
`--textcol Pval n` numbers on the right, `-g` series per row, `--section` headers;
|
|
176
185
|
`fit -o | forest -y marker -x effect --ci cilo,cihi` plots coefficients). `-g COL`
|
|
177
186
|
overlays groups, `--subgraphcol COL` makes panels. `scat`, `line`, `hist` take
|
|
178
|
-
`--vline X[:LABEL]` / `--hline Y[:LABEL]` reference lines (`forest` takes `--vline`, `box` `--hline`)
|
|
187
|
+
`--vline X[:LABEL]` / `--hline Y[:LABEL]` reference lines (`forest` takes `--vline`, `box` `--hline`);
|
|
188
|
+
`scat`, `line` take `--abline A:B[:LABEL]` for y = A + B*x (bare: y = x; `--abline=-1:2` for a
|
|
189
|
+
negative intercept).
|
|
179
190
|
|
|
180
191
|
Other: `dataset NAME` loads a bundled example table, `annotate FILE.parquet`
|
|
181
192
|
reads and writes provenance metadata, `clean` removes leftover temp pipe
|
|
182
|
-
files, `skill install` installs this skill for Claude Code and Codex
|
|
193
|
+
files, `skill install` installs this skill for Claude Code and Codex,
|
|
194
|
+
`completion install` sets up Tab completion in bash or zsh.
|
|
183
195
|
|
|
184
196
|
## Examples
|
|
185
197
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dataframe_toolkit-0.28.0 → dataframe_toolkit-0.30.0}/src/dftk/skills/dftk/references/snakemake.md
RENAMED
|
File without changes
|