http://tiny.cc/nuff
nuff: one tiny file of reusable Python tricks — attribute-dicts,
typed CSV, pretty-print, seeded randomness, non-parametric stats,
minimal column summaries, and row distances. Pure stdlib, zero
dependencies. The cut-down kernel under my bigger apps, with no
global config: every parameter (p, cliff, conf, rng) is
passed as a keyword, so any function lifts out into another project.
from nuff import o, csv, say, Data, disty, same, shuffle
import random
d = Data(csv("../optimiz/auto93.csv")) # build a table
say(disty(d, d.rows[0], p=1)) # row->goal distance, p a kwarg
shuffle(rows, rng=random.Random(1)) # repeatable, own RNG
same(a, b, cliff=0.195, conf=1.36) # are two samples the same?
Sections: NAME | DESIGN | API | STYLE | LICENSE | AUTHOR
Files: nuff.py | test_nuff.py | Makefile | pyproject.toml
NAME
nuff - one file of tiny stdlib python tricks (no global config)
DESIGN
One file, themed sections, no module-level `the`. Tuning rides
along as keyword args, so any function drops into another app:
disty(data, row, p=2)
same(xs, ys, cliff=0.195, conf=1.36)
shuffle(lst, rng=random.Random(seed))
API
records / io / format
o(dict) attribute access: d.x is d['x']
thing(s) coerce str -> int|float|bool|str
settings(s) every var=val in s -> an o (vals coerced)
csv(file) yield typed rows ('#' = comment)
say(x, dec=2) pretty str; whole floats as ints
main(funs) run funs[name] for each --name in argv
rand (pass your own random.Random(seed) for repeatability)
shuffle(lst, rng) shuffled copy
some(lst, k, rng) sample without replacement
one(lst, rng) one random item
stats (non-parametric "are these two the same?")
cliffs(xs, ys) Cliff's delta effect size 0..1
ks(xs, ys) Kolmogorov-Smirnov CDF gap
same(xs, ys, cliff=.195, conf=1.36)
top_tier(groups, ...) names tied for best (min median)
columns / table (Num, Sym, Cols, Data all just o-records)
Num(txt,at) Sym(txt,at) column summaries (Sym counts in .has)
add(it,v,inc=1) add v to a Num/Sym, or a row to a Data;
inc=-1 subtracts (Num resets if n<2)
adds(src,it) add every item of src to it
mid(col) spread(col) mean/mode, stdev/entropy
norm(col,v) 0..1 via a logistic on v's z-score
Cols(names) -> o(names, all, x, y, klass) by role
Data(rows) -> o(cols, rows); first row = names
clone(data, src=None) new Data, same columns, fresh rows
Upper=Num lower=Sym; +/-/! goal; ! klass; X skip
Data(rows) header sets roles: Upper=Num, lower=Sym,
+/-/! = goal, X = skip
distance (exponent `p` is a keyword)
minkowski(vals, p=2)
disty(data, row, p=2) distance to best goals (0=ideal)
distx(data, r1, r2, p=2) distance between two rows on x
gap(col, u, v) per-column value distance 0..1
bayes (naive bayes; m, k carried as kwargs, no global the)
like(col, v, prior=0, k=1) how a column likes a value
likes(data, row, nrows, nklasses) log-likelihood of a row
confuse(pairs) (want,got) -> per-class
o(pd, pf, prec, acc)
STYLE
Minimal python: one file, one-line comments, ~65-char lines,
very short functions, `i` (not self), records over classes.
Threshold for a new file vs a new gist: parts you *import* stay
in here; *wholes* you *run* (apps, other languages, data) get
their own gist.
LICENSE
MIT. https://choosealicense.com/licenses/mit/
AUTHOR
Tim Menzies <timm@ieee.org>
Release files for nuff 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nuff-0.1.0.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nuff-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / nuff-0.1.0.tar.gz
| Download URL | nuff-0.1.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70f918905bb1958e7eff02b22835d239105319adfd46d1cd996a5e73f133fc9d
|
|
BLAKE2b-256 checksum How to use checksums |
36351102a2d2cff87867e64fca1dc83e3140fc2580b46adca3df92ae9e4e5b12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0rc1
|
Release files / nuff-0.1.0-py3-none-any.whl
| Download URL | nuff-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
377ad3399155da46ba5f28ce2d168417bc74c17a4a645f3255253f51ac319c4c
|
|
BLAKE2b-256 checksum How to use checksums |
7fad91a1a1fffdd71225ea395d53aa5acbc5463e31037ecae3df2462b2e86f06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0rc1
|