dataframe-toolkit 0.11.2__tar.gz → 0.11.3__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 (51) hide show
  1. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/PKG-INFO +66 -1
  2. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/README.md +64 -0
  3. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/pyproject.toml +2 -1
  4. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/pyproject.toml.orig +2 -1
  5. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/eval_cmd.py +18 -0
  6. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/query_cmd.py +22 -0
  7. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/__init__.py +0 -0
  8. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/cli.py +0 -0
  9. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/__init__.py +0 -0
  10. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/annotate_cmd.py +0 -0
  11. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/base.py +0 -0
  12. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/binx_cmd.py +0 -0
  13. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/chi_cmd.py +0 -0
  14. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/clean_cmd.py +0 -0
  15. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/cleannames_cmd.py +0 -0
  16. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/concat_cmd.py +0 -0
  17. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/corr_cmd.py +0 -0
  18. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/dataset_cmd.py +0 -0
  19. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/describe_cmd.py +0 -0
  20. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/explode_cmd.py +0 -0
  21. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/fit_cmd.py +0 -0
  22. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/func_cmd.py +0 -0
  23. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/help.py +0 -0
  24. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/hist_cmd.py +0 -0
  25. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/implode_cmd.py +0 -0
  26. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/info_cmd.py +0 -0
  27. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/interp_cmd.py +0 -0
  28. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/line_cmd.py +0 -0
  29. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/melt_cmd.py +0 -0
  30. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/merge_cmd.py +0 -0
  31. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/pivot_cmd.py +0 -0
  32. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/print_cmd.py +0 -0
  33. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/randvar_cmd.py +0 -0
  34. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/sample_cmd.py +0 -0
  35. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/scale_cmd.py +0 -0
  36. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/scat_cmd.py +0 -0
  37. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/segid_cmd.py +0 -0
  38. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/split_cmd.py +0 -0
  39. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/stat_cmd.py +0 -0
  40. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/test_cmd.py +0 -0
  41. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/transpose_cmd.py +0 -0
  42. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/commands/wstat_cmd.py +0 -0
  43. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/__init__.py +0 -0
  44. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/copula.py +0 -0
  45. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/evalfuncs.py +0 -0
  46. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/io.py +0 -0
  47. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/plot.py +0 -0
  48. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/seed.py +0 -0
  49. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/seq.py +0 -0
  50. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/common/stats.py +0 -0
  51. {dataframe_toolkit-0.11.2 → dataframe_toolkit-0.11.3}/src/dftk/io.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dataframe-toolkit
3
- Version: 0.11.2
3
+ Version: 0.11.3
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
@@ -20,6 +20,7 @@ Requires-Dist: statsmodels>=0.14
20
20
  Requires-Dist: patsy>=0.5.6
21
21
  Requires-Dist: duckdb>=0.8
22
22
  Requires-Dist: matplotlib>=3.7
23
+ Requires-Dist: pillow>=13.0
23
24
  Requires-Dist: seaborn>=0.12
24
25
  Requires-Dist: tqdm>=4.65
25
26
  Requires-Python: >=3.12
@@ -298,6 +299,70 @@ dftk dataset healthexp -o \
298
299
  --drop before after
299
300
  ```
300
301
 
302
+ ### Differences between rows
303
+
304
+ For the change in a column from one row to the next, `eval -f` takes
305
+ pandas `diff()` and `pct_change()`, also within groups. They use the rows
306
+ in their order, so sort first, in a step of its own:
307
+
308
+ ```bash
309
+ dftk dataset healthexp -o | dftk eval ... --sortasc Country Year -o \
310
+ | dftk eval ... -f "change = Spending_USD.groupby(Country).diff().round(1)" \
311
+ -f "pct = (Spending_USD.groupby(Country).pct_change() * 100).round(1)" \
312
+ -f "years = Year.groupby(Country).diff()"
313
+ ```
314
+
315
+ ```text
316
+ Year Country Spending_USD Life_Expectancy change pct years
317
+ 1971 Canada 313.391 72.8
318
+ 1976 Canada 543.337 73.8 229.9 73.4 5.0
319
+ 1979 Canada 692.269 75.1 148.9 27.4 3.0
320
+ 1980 Canada 791.812 75.2 99.5 14.4 1.0
321
+ ```
322
+
323
+ The first row of each country gets an empty cell. Without
324
+ `groupby(Country)`, it would be compared with the last row of the
325
+ previous country.
326
+
327
+ To compare a value with one in another column of the previous or next row, for example the
328
+ gap between segments given by `Chr`, `Begin`, `End`, use SQL's `LAG()` /
329
+ `LEAD()` in `query --sql`:
330
+
331
+ ```bash
332
+ dftk query segments.tsv --sql \
333
+ 'SELECT *, "Begin" - LAG("End") OVER (PARTITION BY Chr ORDER BY "Begin")
334
+ AS gap
335
+ FROM data ORDER BY Chr, "Begin"'
336
+ ```
337
+
338
+ ```text
339
+ Chr Begin End Id gap
340
+ chr1 100 200 a
341
+ chr1 250 400 b 50
342
+ chr1 390 500 c -10
343
+ chr2 50 80 d
344
+ chr2 100 300 e 20
345
+ ```
346
+
347
+ A negative gap is an overlap, and the first segment on each chromosome
348
+ gets an empty cell. `lead("Begin") OVER (...) - "End"` gives the gap to
349
+ the next segment instead.
350
+
351
+ - `Begin` and `End` are SQL keywords: quote such column names with double
352
+ quotes and the whole statement with single quotes.
353
+ - No sorting is needed first; `ORDER BY` inside `OVER` sets the order.
354
+ - Integers stay integers.
355
+
356
+ `eval -f` can do the same with pandas `shift`, but it goes by row order, so
357
+ sort by `Chr` and `Begin` first (results are floats):
358
+
359
+ ```bash
360
+ dftk eval segments.tsv -f 'gap = Begin - End.groupby(Chr).shift()'
361
+ ```
362
+
363
+ Without `groupby(Chr)` the first segment of a chromosome is compared with
364
+ the last one of the previous chromosome.
365
+
301
366
  ### Bootstrap confidence intervals
302
367
 
303
368
  Bootstrap mode repeats the full stat computation N times on resampled data
@@ -269,6 +269,70 @@ dftk dataset healthexp -o \
269
269
  --drop before after
270
270
  ```
271
271
 
272
+ ### Differences between rows
273
+
274
+ For the change in a column from one row to the next, `eval -f` takes
275
+ pandas `diff()` and `pct_change()`, also within groups. They use the rows
276
+ in their order, so sort first, in a step of its own:
277
+
278
+ ```bash
279
+ dftk dataset healthexp -o | dftk eval ... --sortasc Country Year -o \
280
+ | dftk eval ... -f "change = Spending_USD.groupby(Country).diff().round(1)" \
281
+ -f "pct = (Spending_USD.groupby(Country).pct_change() * 100).round(1)" \
282
+ -f "years = Year.groupby(Country).diff()"
283
+ ```
284
+
285
+ ```text
286
+ Year Country Spending_USD Life_Expectancy change pct years
287
+ 1971 Canada 313.391 72.8
288
+ 1976 Canada 543.337 73.8 229.9 73.4 5.0
289
+ 1979 Canada 692.269 75.1 148.9 27.4 3.0
290
+ 1980 Canada 791.812 75.2 99.5 14.4 1.0
291
+ ```
292
+
293
+ The first row of each country gets an empty cell. Without
294
+ `groupby(Country)`, it would be compared with the last row of the
295
+ previous country.
296
+
297
+ To compare a value with one in another column of the previous or next row, for example the
298
+ gap between segments given by `Chr`, `Begin`, `End`, use SQL's `LAG()` /
299
+ `LEAD()` in `query --sql`:
300
+
301
+ ```bash
302
+ dftk query segments.tsv --sql \
303
+ 'SELECT *, "Begin" - LAG("End") OVER (PARTITION BY Chr ORDER BY "Begin")
304
+ AS gap
305
+ FROM data ORDER BY Chr, "Begin"'
306
+ ```
307
+
308
+ ```text
309
+ Chr Begin End Id gap
310
+ chr1 100 200 a
311
+ chr1 250 400 b 50
312
+ chr1 390 500 c -10
313
+ chr2 50 80 d
314
+ chr2 100 300 e 20
315
+ ```
316
+
317
+ A negative gap is an overlap, and the first segment on each chromosome
318
+ gets an empty cell. `lead("Begin") OVER (...) - "End"` gives the gap to
319
+ the next segment instead.
320
+
321
+ - `Begin` and `End` are SQL keywords: quote such column names with double
322
+ quotes and the whole statement with single quotes.
323
+ - No sorting is needed first; `ORDER BY` inside `OVER` sets the order.
324
+ - Integers stay integers.
325
+
326
+ `eval -f` can do the same with pandas `shift`, but it goes by row order, so
327
+ sort by `Chr` and `Begin` first (results are floats):
328
+
329
+ ```bash
330
+ dftk eval segments.tsv -f 'gap = Begin - End.groupby(Chr).shift()'
331
+ ```
332
+
333
+ Without `groupby(Chr)` the first segment of a chromosome is compared with
334
+ the last one of the previous chromosome.
335
+
272
336
  ### Bootstrap confidence intervals
273
337
 
274
338
  Bootstrap mode repeats the full stat computation N times on resampled data
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.11.2"
3
+ version = "0.11.3"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  keywords = [
@@ -29,6 +29,7 @@ dependencies = [
29
29
  "patsy>=0.5.6",
30
30
  "duckdb>=0.8",
31
31
  "matplotlib>=3.7",
32
+ "pillow>=13.0",
32
33
  "seaborn>=0.12",
33
34
  "tqdm>=4.65",
34
35
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.11.2"
3
+ version = "0.11.3"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -26,6 +26,7 @@ dependencies = [
26
26
  "patsy>=0.5.6",
27
27
  "duckdb>=0.8",
28
28
  "matplotlib>=3.7",
29
+ "pillow>=13.0", # not used directly (matplotlib needs it); floor for security fixes
29
30
  "seaborn>=0.12",
30
31
  "tqdm>=4.65",
31
32
  ]
@@ -67,6 +67,24 @@ interpolate() has no grouped form. The README ("Filling missing values")
67
67
  covers defaults from a merge, interpolating within groups, and more.
68
68
 
69
69
 
70
+ DIFFERENCES BETWEEN ROWS (-f)
71
+ -----------------------------
72
+ -f "dx = x.diff()" x minus x in the row above
73
+ -f "pct = x.pct_change() * 100" the same as a percentage
74
+ -f "dx = x.groupby(g).diff()" within each group of g
75
+ -f "gap = Begin - End.groupby(Chr).shift()" another column, row above
76
+
77
+ Like ffill, these use the rows in their order, so sort first, in a step
78
+ of its own; the first row of each group gets an empty cell:
79
+
80
+ dftk dataset healthexp -o | dftk eval ... --sortasc Country Year -o \\
81
+ | dftk eval ... -f "change = Spending_USD.groupby(Country).diff().round(1)" \\
82
+ -f "years = Year.groupby(Country).diff()"
83
+
84
+ query --sql with LAG()/LEAD() does the same without sorting first and
85
+ keeps integers integers (see query -h).
86
+
87
+
70
88
  DFTK FUNCTIONS (-f)
71
89
  -------------------
72
90
  A formula whose right-hand side is one call to a function below runs that
@@ -166,6 +166,28 @@ Window functions:
166
166
  "SELECT *, ROW_NUMBER() OVER (PARTITION BY cut ORDER BY price DESC) AS rank
167
167
  FROM data"
168
168
 
169
+ Differences between rows: LAG() and LEAD() read a column in the previous
170
+ or next row of the window, so one row's start can be compared with the
171
+ previous row's end. Gaps between segments on each chromosome (negative =
172
+ overlap; the first segment of each chromosome gets an empty cell):
173
+
174
+ dftk query segments.tsv --sql \\
175
+ 'SELECT *, "Begin" - LAG("End") OVER (PARTITION BY Chr ORDER BY "Begin")
176
+ AS gap
177
+ FROM data ORDER BY Chr, "Begin"'
178
+
179
+ Begin and End are SQL keywords: put such column names in double quotes,
180
+ and the whole statement in single quotes. No sorting is needed first;
181
+ ORDER BY inside OVER sets the row order. The same on a bundled dataset,
182
+ change since the previous record and years between records per country:
183
+
184
+ dftk dataset healthexp -o | dftk query ... --sql \\
185
+ "SELECT Country, Year, Spending_USD,
186
+ ROUND(Spending_USD - LAG(Spending_USD) OVER w, 1) AS change,
187
+ Year - LAG(Year) OVER w AS years
188
+ FROM data WINDOW w AS (PARTITION BY Country ORDER BY Year)
189
+ ORDER BY Country, Year"
190
+
169
191
  CTEs:
170
192
 
171
193
  dftk dataset diamonds -o | dftk query ... --sql \\