dataframe-toolkit 0.5.0__tar.gz → 0.7.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.
Files changed (47) hide show
  1. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/PKG-INFO +76 -38
  2. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/README.md +75 -37
  3. dataframe_toolkit-0.7.0/pyproject.toml +82 -0
  4. dataframe_toolkit-0.5.0/pyproject.toml → dataframe_toolkit-0.7.0/pyproject.toml.orig +1 -1
  5. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/cli.py +9 -0
  6. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/__init__.py +2 -0
  7. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/annotate_cmd.py +4 -0
  8. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/binx_cmd.py +4 -2
  9. dataframe_toolkit-0.7.0/src/dftk/commands/chi_cmd.py +193 -0
  10. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/concat_cmd.py +15 -12
  11. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/corr_cmd.py +92 -9
  12. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/describe_cmd.py +4 -4
  13. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/eval_cmd.py +6 -5
  14. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/fit_cmd.py +6 -5
  15. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/func_cmd.py +6 -5
  16. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/hist_cmd.py +13 -11
  17. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/info_cmd.py +5 -1
  18. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/interp_cmd.py +35 -13
  19. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/line_cmd.py +25 -12
  20. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/melt_cmd.py +20 -10
  21. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/merge_cmd.py +34 -13
  22. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/pivot_cmd.py +34 -21
  23. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/print_cmd.py +1 -4
  24. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/query_cmd.py +31 -22
  25. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/randvar_cmd.py +5 -1
  26. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/sample_cmd.py +9 -7
  27. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/scale_cmd.py +24 -12
  28. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/scat_cmd.py +10 -7
  29. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/segid_cmd.py +7 -0
  30. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/split_cmd.py +8 -5
  31. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/stat_cmd.py +17 -6
  32. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/test_cmd.py +11 -2
  33. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/transpose_cmd.py +12 -0
  34. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/wstat_cmd.py +7 -7
  35. dataframe_toolkit-0.7.0/src/dftk/common/copula.py +213 -0
  36. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/io.py +11 -24
  37. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/plot.py +80 -7
  38. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/__init__.py +0 -0
  39. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/base.py +0 -0
  40. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/clean_cmd.py +0 -0
  41. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/dataset_cmd.py +0 -0
  42. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/commands/help.py +0 -0
  43. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/__init__.py +0 -0
  44. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/seed.py +0 -0
  45. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/seq.py +0 -0
  46. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/common/stats.py +0 -0
  47. {dataframe_toolkit-0.5.0 → dataframe_toolkit-0.7.0}/src/dftk/io.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dataframe-toolkit
3
- Version: 0.5.0
3
+ Version: 0.7.0
4
4
  Summary: A command-line toolkit for DataFrame analysis and manipulation
5
5
  Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
6
6
  Author: Gunnar Pálsson
@@ -38,6 +38,14 @@ for analysts who live in the terminal and want a consistent, pipeable toolkit
38
38
  for the full data analysis pipeline — from initial exploration through
39
39
  statistical modelling and publication-quality figures.
40
40
 
41
+ **No data file handy?** Every example below uses `dftk dataset` to pull in a
42
+ small, real dataset, so you can copy-paste any of them and run them right
43
+ now. Run `dftk dataset --list` to browse everything available (dozens of
44
+ datasets from seaborn, statsmodels, and pydataset). `dftk dataset NAME`
45
+ searches all three sources in that order and returns the first match, so
46
+ `--source` is optional — pass it only to disambiguate a name that exists in
47
+ more than one source, or to restrict the search.
48
+
41
49
  ## Installation
42
50
 
43
51
  ```bash
@@ -68,28 +76,38 @@ uv tool install .
68
76
  ## Quick example
69
77
 
70
78
  ```bash
71
- dftk stat data.tsv -c height weight -g sex
72
- dftk stat data.tsv -c value -g group -o \
73
- | dftk pivot -i group -v value_mean -o \
74
- | dftk print
79
+ dftk dataset tips | dftk stat - -c tip total_bill -g day
80
+ ```
81
+
82
+ Chain commands with `-o` (write to a temp parquet, print its path) and `...`
83
+ (read a parquet path from stdin) instead of piping TSV text directly — faster
84
+ for large data, and the recommended pattern once a pipeline has more than one
85
+ step:
86
+
87
+ ```bash
88
+ dftk dataset tips -o \
89
+ | dftk pivot ... -i day -v tip -f mean -o \
90
+ | dftk print ...
75
91
  ```
76
92
 
77
93
  ## Subcommands
78
94
 
79
95
  ### Data transformation
80
96
 
81
- | Command | Description |
82
- |-----------|--------------------------------------------------------------------------------------|
83
- | `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
84
- | `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
85
- | `merge` | Join two tables on key columns (inner/left/right/outer) |
86
- | `concat` | Concatenate two or more tables row-wise |
87
- | `melt` | Reshape wide-to-long (`pd.melt`) |
88
- | `pivot` | Reshape long-to-wide with per-cell aggregation |
89
- | `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
90
- | `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
91
- | `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
92
- | `binx` | Assign bin indices to a column based on explicit or generated edges |
97
+ | Command | Description |
98
+ |-------------|---------------------------------------------------------------------------------------|
99
+ | `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
100
+ | `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
101
+ | `merge` | Join two tables on key columns (inner/left/right/outer) |
102
+ | `concat` | Concatenate two or more tables row-wise |
103
+ | `melt` | Reshape wide-to-long (`pd.melt`) |
104
+ | `pivot` | Reshape long-to-wide with per-cell aggregation |
105
+ | `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
106
+ | `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
107
+ | `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
108
+ | `binx` | Assign bin indices to a column based on explicit or generated edges |
109
+ | `transpose` | Flip rows and columns; original column names land in a new `--keycol` column |
110
+ | `segid` | Assign a segment ID that increments on each value change in a column |
93
111
 
94
112
  ### Statistics
95
113
 
@@ -101,6 +119,7 @@ dftk stat data.tsv -c value -g group -o \
101
119
  | `test` | P-values between column pairs: t-test, Mann-Whitney, Wilcoxon, KS, correlations, bootstrap; groups |
102
120
  | `corr` | Pairwise column correlations (Pearson/Spearman/Kendall) with optional BCa bootstrap CI |
103
121
  | `describe` | Quick column-level summary (dtype, n, n_unique, n_null, sample values) |
122
+ | `info` | Per-column dtype, null counts, and memory usage; `--summary` for dataset-level totals |
104
123
  | `randvar` | Sample from a distribution and append as a new column (norm, alpha, beta, …) |
105
124
 
106
125
  ### Plots
@@ -133,38 +152,48 @@ publication-quality output.
133
152
  ### Chaining commands
134
153
 
135
154
  ```bash
136
- # z-score within group, then fit a model
137
- dftk scale data.tsv -c expr -g condition -o \
138
- | dftk fit - -f "expr_z ~ time + batch" -g condition
155
+ # z-score sepal_length within species, then fit against petal_length
156
+ dftk dataset iris -o \
157
+ | dftk scale ... -c sepal_length -g species -o \
158
+ | dftk fit ... -f "sepal_length_scaled ~ petal_length" -g species
139
159
  ```
140
160
 
141
161
  ### Group summary then plot
142
162
 
143
163
  ```bash
144
- dftk stat results.tsv -c value -g group -o \
145
- | dftk line - -x group -y value_mean --yerr value_sem -f fig.png
164
+ dftk dataset tips -o \
165
+ | dftk stat ... -c tip -g day -o \
166
+ | dftk line ... -x day -y mean --yerr sem -f fig.png
146
167
  ```
147
168
 
148
169
  ### Wide-to-long then plot overlaid histograms
149
170
 
150
171
  ```bash
151
- dftk melt data.tsv -i sample -d gene -v expression \
152
- | dftk hist - -x expression -g gene -k -f dist.png
172
+ dftk dataset iris \
173
+ | dftk melt - -i species -d measurement -v value \
174
+ | dftk hist - -x value -g measurement -k -f dist.png
153
175
  ```
154
176
 
155
177
  ### Interpolation (standard curve lookup)
156
178
 
157
179
  ```bash
158
- dftk interp samples.tsv --ref stdcurve.tsv \
159
- -x fluorescence -v concentration -d conc_ng_ul
180
+ printf "conc\tfluor\n0\t5\n10\t52\n20\t98\n30\t151\n" > stdcurve.tsv
181
+ printf "sample\tfluor\ns1\t60\ns2\t110\n" \
182
+ | dftk interp - --ref stdcurve.tsv -x fluor --refx fluor -v conc -d conc_ng_ul
160
183
  ```
161
184
 
162
185
  ### Bootstrap confidence intervals
163
186
 
187
+ Bootstrap mode repeats the full stat computation N times on resampled data
188
+ and emits one row per resample (tagged with `samplenum`) — pipe into `pivot`
189
+ with percentile aggfuncs (`cilo`/`cihi`) to collapse that into an empirical
190
+ confidence interval:
191
+
164
192
  ```bash
165
- dftk stat data.tsv -c value -g group --bootstrap 1000 --randomseed 42 -o \
166
- | dftk pivot -i group -v value_mean -f mean -o \
167
- | dftk stat - -c group_A group_B
193
+ dftk dataset tips -o \
194
+ | dftk stat ... -c tip -g day --bootstrap 1000 --randomseed 42 -o \
195
+ | dftk pivot ... -i day -v mean -f mean cilo cihi -o \
196
+ | dftk print ...
168
197
  ```
169
198
 
170
199
  ## Input/output
@@ -176,9 +205,19 @@ All commands accept:
176
205
  - `...` to receive a parquet path from stdin (written by a previous `-o` command)
177
206
  - A `.parquet` filename to read a named parquet file directly
178
207
 
208
+ > **`-` vs `...`** — these are not interchangeable. Use `-` when the previous
209
+ > command in the pipe wrote plain TSV to stdout (the default). Use `...` when
210
+ > the previous command used bare `-o` (pipe mode), which writes a temp
211
+ > parquet and prints *its path* to stdout — `-` would try to parse that path
212
+ > as TSV and fail.
213
+
179
214
  Standard output options (available on all tabular commands):
180
215
 
181
- - `-o` / `--output` — write a temp parquet for the next piped command instead of TSV to stdout
216
+ - `-o` / `--output` — controls where output goes; takes an *optional* value:
217
+ - `-o` alone — write a temp parquet to pipe into the next command, printing its path to stdout (auto-deleted once read)
218
+ - `-o FILE.parquet` — write a named, reusable parquet, printing its path to stdout
219
+ - `-o FILE` (no `.parquet` extension) — write TSV to `FILE`, with no stdout output
220
+ - omit `-o` entirely — write TSV to stdout (the default)
182
221
  - `--select col1 col2 …` — keep only these columns
183
222
  - `--drop col1 col2 …` — remove these columns
184
223
  - `--round N` — round numeric output
@@ -193,20 +232,19 @@ any new `--meta` values.
193
232
 
194
233
  ```bash
195
234
  # Tag a file at creation
196
- dftk eval raw.tsv -f "z = x + y" -o results.parquet \
197
- --meta genome=hg38 --meta source=gwas_2024
235
+ dftk dataset iris -o iris.parquet --meta source=seaborn --meta species_col=species
198
236
 
199
237
  # Inspect annotations
200
- dftk annotate results.parquet
201
- # genome hg38
202
- # source gwas_2024
238
+ dftk annotate iris.parquet
239
+ # source seaborn
240
+ # species_col species
203
241
 
204
242
  # Add or update an annotation in-place
205
- dftk annotate results.parquet --set step=qc_filtered
243
+ dftk annotate iris.parquet --set step=raw
206
244
 
207
245
  # Annotations survive piping
208
- dftk eval results.parquet -f "z_scaled = z / 2" -o | dftk scale ... -c z -o scaled.parquet
209
- dftk annotate scaled.parquet # genome and source still present
246
+ dftk eval iris.parquet -f "petal_area = petal_length * petal_width" -o iris2.parquet
247
+ dftk annotate iris2.parquet # source, species_col, and step all still present
210
248
  ```
211
249
 
212
250
  ## Figure options (plot commands)
@@ -10,6 +10,14 @@ for analysts who live in the terminal and want a consistent, pipeable toolkit
10
10
  for the full data analysis pipeline — from initial exploration through
11
11
  statistical modelling and publication-quality figures.
12
12
 
13
+ **No data file handy?** Every example below uses `dftk dataset` to pull in a
14
+ small, real dataset, so you can copy-paste any of them and run them right
15
+ now. Run `dftk dataset --list` to browse everything available (dozens of
16
+ datasets from seaborn, statsmodels, and pydataset). `dftk dataset NAME`
17
+ searches all three sources in that order and returns the first match, so
18
+ `--source` is optional — pass it only to disambiguate a name that exists in
19
+ more than one source, or to restrict the search.
20
+
13
21
  ## Installation
14
22
 
15
23
  ```bash
@@ -40,28 +48,38 @@ uv tool install .
40
48
  ## Quick example
41
49
 
42
50
  ```bash
43
- dftk stat data.tsv -c height weight -g sex
44
- dftk stat data.tsv -c value -g group -o \
45
- | dftk pivot -i group -v value_mean -o \
46
- | dftk print
51
+ dftk dataset tips | dftk stat - -c tip total_bill -g day
52
+ ```
53
+
54
+ Chain commands with `-o` (write to a temp parquet, print its path) and `...`
55
+ (read a parquet path from stdin) instead of piping TSV text directly — faster
56
+ for large data, and the recommended pattern once a pipeline has more than one
57
+ step:
58
+
59
+ ```bash
60
+ dftk dataset tips -o \
61
+ | dftk pivot ... -i day -v tip -f mean -o \
62
+ | dftk print ...
47
63
  ```
48
64
 
49
65
  ## Subcommands
50
66
 
51
67
  ### Data transformation
52
68
 
53
- | Command | Description |
54
- |-----------|--------------------------------------------------------------------------------------|
55
- | `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
56
- | `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
57
- | `merge` | Join two tables on key columns (inner/left/right/outer) |
58
- | `concat` | Concatenate two or more tables row-wise |
59
- | `melt` | Reshape wide-to-long (`pd.melt`) |
60
- | `pivot` | Reshape long-to-wide with per-cell aggregation |
61
- | `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
62
- | `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
63
- | `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
64
- | `binx` | Assign bin indices to a column based on explicit or generated edges |
69
+ | Command | Description |
70
+ |-------------|---------------------------------------------------------------------------------------|
71
+ | `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
72
+ | `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
73
+ | `merge` | Join two tables on key columns (inner/left/right/outer) |
74
+ | `concat` | Concatenate two or more tables row-wise |
75
+ | `melt` | Reshape wide-to-long (`pd.melt`) |
76
+ | `pivot` | Reshape long-to-wide with per-cell aggregation |
77
+ | `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
78
+ | `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
79
+ | `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
80
+ | `binx` | Assign bin indices to a column based on explicit or generated edges |
81
+ | `transpose` | Flip rows and columns; original column names land in a new `--keycol` column |
82
+ | `segid` | Assign a segment ID that increments on each value change in a column |
65
83
 
66
84
  ### Statistics
67
85
 
@@ -73,6 +91,7 @@ dftk stat data.tsv -c value -g group -o \
73
91
  | `test` | P-values between column pairs: t-test, Mann-Whitney, Wilcoxon, KS, correlations, bootstrap; groups |
74
92
  | `corr` | Pairwise column correlations (Pearson/Spearman/Kendall) with optional BCa bootstrap CI |
75
93
  | `describe` | Quick column-level summary (dtype, n, n_unique, n_null, sample values) |
94
+ | `info` | Per-column dtype, null counts, and memory usage; `--summary` for dataset-level totals |
76
95
  | `randvar` | Sample from a distribution and append as a new column (norm, alpha, beta, …) |
77
96
 
78
97
  ### Plots
@@ -105,38 +124,48 @@ publication-quality output.
105
124
  ### Chaining commands
106
125
 
107
126
  ```bash
108
- # z-score within group, then fit a model
109
- dftk scale data.tsv -c expr -g condition -o \
110
- | dftk fit - -f "expr_z ~ time + batch" -g condition
127
+ # z-score sepal_length within species, then fit against petal_length
128
+ dftk dataset iris -o \
129
+ | dftk scale ... -c sepal_length -g species -o \
130
+ | dftk fit ... -f "sepal_length_scaled ~ petal_length" -g species
111
131
  ```
112
132
 
113
133
  ### Group summary then plot
114
134
 
115
135
  ```bash
116
- dftk stat results.tsv -c value -g group -o \
117
- | dftk line - -x group -y value_mean --yerr value_sem -f fig.png
136
+ dftk dataset tips -o \
137
+ | dftk stat ... -c tip -g day -o \
138
+ | dftk line ... -x day -y mean --yerr sem -f fig.png
118
139
  ```
119
140
 
120
141
  ### Wide-to-long then plot overlaid histograms
121
142
 
122
143
  ```bash
123
- dftk melt data.tsv -i sample -d gene -v expression \
124
- | dftk hist - -x expression -g gene -k -f dist.png
144
+ dftk dataset iris \
145
+ | dftk melt - -i species -d measurement -v value \
146
+ | dftk hist - -x value -g measurement -k -f dist.png
125
147
  ```
126
148
 
127
149
  ### Interpolation (standard curve lookup)
128
150
 
129
151
  ```bash
130
- dftk interp samples.tsv --ref stdcurve.tsv \
131
- -x fluorescence -v concentration -d conc_ng_ul
152
+ printf "conc\tfluor\n0\t5\n10\t52\n20\t98\n30\t151\n" > stdcurve.tsv
153
+ printf "sample\tfluor\ns1\t60\ns2\t110\n" \
154
+ | dftk interp - --ref stdcurve.tsv -x fluor --refx fluor -v conc -d conc_ng_ul
132
155
  ```
133
156
 
134
157
  ### Bootstrap confidence intervals
135
158
 
159
+ Bootstrap mode repeats the full stat computation N times on resampled data
160
+ and emits one row per resample (tagged with `samplenum`) — pipe into `pivot`
161
+ with percentile aggfuncs (`cilo`/`cihi`) to collapse that into an empirical
162
+ confidence interval:
163
+
136
164
  ```bash
137
- dftk stat data.tsv -c value -g group --bootstrap 1000 --randomseed 42 -o \
138
- | dftk pivot -i group -v value_mean -f mean -o \
139
- | dftk stat - -c group_A group_B
165
+ dftk dataset tips -o \
166
+ | dftk stat ... -c tip -g day --bootstrap 1000 --randomseed 42 -o \
167
+ | dftk pivot ... -i day -v mean -f mean cilo cihi -o \
168
+ | dftk print ...
140
169
  ```
141
170
 
142
171
  ## Input/output
@@ -148,9 +177,19 @@ All commands accept:
148
177
  - `...` to receive a parquet path from stdin (written by a previous `-o` command)
149
178
  - A `.parquet` filename to read a named parquet file directly
150
179
 
180
+ > **`-` vs `...`** — these are not interchangeable. Use `-` when the previous
181
+ > command in the pipe wrote plain TSV to stdout (the default). Use `...` when
182
+ > the previous command used bare `-o` (pipe mode), which writes a temp
183
+ > parquet and prints *its path* to stdout — `-` would try to parse that path
184
+ > as TSV and fail.
185
+
151
186
  Standard output options (available on all tabular commands):
152
187
 
153
- - `-o` / `--output` — write a temp parquet for the next piped command instead of TSV to stdout
188
+ - `-o` / `--output` — controls where output goes; takes an *optional* value:
189
+ - `-o` alone — write a temp parquet to pipe into the next command, printing its path to stdout (auto-deleted once read)
190
+ - `-o FILE.parquet` — write a named, reusable parquet, printing its path to stdout
191
+ - `-o FILE` (no `.parquet` extension) — write TSV to `FILE`, with no stdout output
192
+ - omit `-o` entirely — write TSV to stdout (the default)
154
193
  - `--select col1 col2 …` — keep only these columns
155
194
  - `--drop col1 col2 …` — remove these columns
156
195
  - `--round N` — round numeric output
@@ -165,20 +204,19 @@ any new `--meta` values.
165
204
 
166
205
  ```bash
167
206
  # Tag a file at creation
168
- dftk eval raw.tsv -f "z = x + y" -o results.parquet \
169
- --meta genome=hg38 --meta source=gwas_2024
207
+ dftk dataset iris -o iris.parquet --meta source=seaborn --meta species_col=species
170
208
 
171
209
  # Inspect annotations
172
- dftk annotate results.parquet
173
- # genome hg38
174
- # source gwas_2024
210
+ dftk annotate iris.parquet
211
+ # source seaborn
212
+ # species_col species
175
213
 
176
214
  # Add or update an annotation in-place
177
- dftk annotate results.parquet --set step=qc_filtered
215
+ dftk annotate iris.parquet --set step=raw
178
216
 
179
217
  # Annotations survive piping
180
- dftk eval results.parquet -f "z_scaled = z / 2" -o | dftk scale ... -c z -o scaled.parquet
181
- dftk annotate scaled.parquet # genome and source still present
218
+ dftk eval iris.parquet -f "petal_area = petal_length * petal_width" -o iris2.parquet
219
+ dftk annotate iris2.parquet # source, species_col, and step all still present
182
220
  ```
183
221
 
184
222
  ## Figure options (plot commands)
@@ -0,0 +1,82 @@
1
+ [project]
2
+ name = "dataframe-toolkit"
3
+ version = "0.7.0"
4
+ description = "A command-line toolkit for DataFrame analysis and manipulation"
5
+ readme = "README.md"
6
+ keywords = [
7
+ "dataframe",
8
+ "statistics",
9
+ "data analysis",
10
+ "CLI",
11
+ "TSV",
12
+ "pandas",
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Science/Research",
17
+ "Intended Audience :: Developers",
18
+ "Topic :: Scientific/Engineering :: Information Analysis",
19
+ "Topic :: Utilities",
20
+ "Programming Language :: Python :: 3",
21
+ ]
22
+ requires-python = ">=3.12"
23
+ dependencies = [
24
+ "pandas>=2.1",
25
+ "numpy>=1.24",
26
+ "pyarrow>=12.0",
27
+ "scipy>=1.10",
28
+ "statsmodels>=0.14",
29
+ "duckdb>=0.8",
30
+ "matplotlib>=3.7",
31
+ "seaborn>=0.12",
32
+ "tqdm>=4.65",
33
+ ]
34
+
35
+ [[project.authors]]
36
+ name = "Gunnar Pálsson"
37
+ email = "hemingur@gmail.com"
38
+
39
+ [project.license]
40
+ text = "MIT"
41
+
42
+ [project.urls]
43
+ Homepage = "https://github.com/hemingur/dataframe-toolkit"
44
+ Repository = "https://github.com/hemingur/dataframe-toolkit"
45
+
46
+ [project.scripts]
47
+ dftk = "dftk.cli:main"
48
+
49
+ [build-system]
50
+ requires = ["uv_build>=0.10.4,<0.11.0"]
51
+ build-backend = "uv_build"
52
+
53
+ [tool.uv.build-backend]
54
+ module-name = "dftk"
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
58
+
59
+ [tool.ruff]
60
+ line-length = 88
61
+ target-version = "py312"
62
+
63
+ [tool.ruff.lint]
64
+ select = [
65
+ "E",
66
+ "W",
67
+ "F",
68
+ "I",
69
+ "UP",
70
+ "B",
71
+ ]
72
+
73
+ [tool.ruff.lint.isort]
74
+ known-first-party = ["dftk"]
75
+
76
+ [dependency-groups]
77
+ dev = [
78
+ "pre-commit>=4.6.0",
79
+ "pytest>=8.0",
80
+ "pytest-cov>=7.1.0",
81
+ "ruff>=0.15.12",
82
+ ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.5.0"
3
+ version = "0.7.0"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -8,6 +8,8 @@ logic and never needs to change when a new subcommand is added.
8
8
 
9
9
  import argparse
10
10
  import logging
11
+ import os
12
+ import signal
11
13
  import sys
12
14
 
13
15
  from dftk import __version__
@@ -47,6 +49,13 @@ def main() -> None:
47
49
 
48
50
  try:
49
51
  args.command_instance.execute(args)
52
+ sys.stdout.flush()
53
+ except BrokenPipeError:
54
+ # The reader closed the pipe early (e.g. `dftk ... | head`). Exit
55
+ # quietly with the SIGPIPE status like cat/grep, and point stdout at
56
+ # devnull so the interpreter's final flush doesn't raise again.
57
+ os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
58
+ sys.exit(128 + signal.SIGPIPE)
50
59
  except FileNotFoundError as exc:
51
60
  print(f"File error: {exc}", file=sys.stderr)
52
61
  sys.exit(1)
@@ -8,6 +8,7 @@
8
8
 
9
9
  from dftk.commands.annotate_cmd import AnnotateCommand
10
10
  from dftk.commands.binx_cmd import BinxCommand
11
+ from dftk.commands.chi_cmd import ChiCommand
11
12
  from dftk.commands.clean_cmd import CleanCommand
12
13
  from dftk.commands.concat_cmd import ConcatCommand
13
14
  from dftk.commands.corr_cmd import CorrCommand
@@ -80,6 +81,7 @@ COMMAND_GROUPS: list[tuple[str, list]] = [
80
81
  ScatCommand(),
81
82
  LineCommand(),
82
83
  HistCommand(),
84
+ ChiCommand(),
83
85
  ],
84
86
  ),
85
87
  (
@@ -25,6 +25,10 @@ Usage examples:
25
25
  dftk eval data.tsv -f "z = x + y" -o result.parquet \\
26
26
  --meta genome=hg38 --meta source=my_pipeline
27
27
 
28
+ # Same, built from a bundled dataset:
29
+ dftk dataset iris -o | dftk eval ... -f "z = sepal_length + petal_length" \\
30
+ -o result.parquet --meta genome=hg38 --meta source=my_pipeline
31
+
28
32
  Annotations propagate through the parquet pipe: a file annotated at
29
33
  creation is re-annotated on every subsequent -o write unless explicitly
30
34
  overridden.
@@ -74,8 +74,10 @@ USEVALUE (--usevalue)
74
74
  EXAMPLES
75
75
  --------
76
76
  dftk binx data.tsv -c age -b 0:100:10
77
- dftk binx data.tsv -c score -b 0,25,50,75,100 -d quartile --usevalue m
78
- dftk binx data.tsv -c x -b -3:4:1 -d x_bin -o | dftk stat -g x_bin -s y
77
+ dftk dataset tips -o | dftk binx ... -c total_bill -b 0:60:10
78
+ dftk dataset tips -o | dftk binx ... -c tip -b 0,2,4,6,10 -d tip_bracket --usevalue m
79
+ dftk dataset tips -o | dftk binx ... -c total_bill -b 0:60:10 -d bill_bin -o \\
80
+ | dftk stat ... -c tip -g bill_bin
79
81
  """
80
82
 
81
83