2021-06-15 ward + pytest-clarity + postgresql chart + sphinxcontrib.datatemplates + using-djangos-manytomanyfield ¶
Ward 0.61.1b0 - Allow Click 7+ ¶
-
https://github.com/darrenburns/ward/releases/tag/release%2F0.61.1b0
-
https://twitter.com/_darrenburns/status/1401219181299834889?s=20
Ward 0.60.0b is now on PyPI Bombe de table Shaves 10-20% overhead off of test duration, adds « live » output mode (see video), and pretty output for « assert x in y » failures. Thanks to @__jtk__ ! #python #testing
A plugin to improve the output of pytest with colourful unified diffs ¶
I’ve released pytest-clarity 1.0.0 🙂 It makes the diff output from Ward available to #pytest users via a plugin. #python #testing
PostgreSQL ¶
In my recent article I showed how to produce an equal width histogram with #SQL using width_bucket or a custom axis.
https://hakibenita.com/sql-for-data-analysis#equal-width-binning
Today I found that custom range types in #PostgreSQL come in very handy for histograms! As a bonus, they handle unbounded ranges!
WITH grades AS (
SELECT round(70 + sin(n) * 30)::int AS grade
FROM generate_series(1, 100) AS n
),
buckets AS (
SELECT
bucket,
(bucket - 1) * 5 + 1 AS low_bound,
bucket * 5 AS high_bound
FROM
generate_series(1, 20) AS bucket
)
SELECT
low_bound || ' - ' || high_bound as bounds,
COUNT(grade) AS cnt,
repeat('■', COUNT(grade)::int) as chart
FROM
buckets
LEFT JOIN grades ON grade BETWEEN low_bound AND high_bound
GROUP BY
bucket, low_bound, high_bound
ORDER BY
bucket;
bounds |cnt|chart |
--------+---+------------------+
1 - 5 | 0| |
6 - 10 | 0| |
11 - 15 | 0| |
16 - 20 | 0| |
21 - 25 | 0| |
26 - 30 | 0| |
31 - 35 | 0| |
36 - 40 | 7|■■■■■■■ |
41 - 45 | 13|■■■■■■■■■■■■■ |
46 - 50 | 7|■■■■■■■ |
51 - 55 | 8|■■■■■■■■ |
56 - 60 | 4|■■■■ |
61 - 65 | 7|■■■■■■■ |
66 - 70 | 4|■■■■ |
71 - 75 | 7|■■■■■■■ |
76 - 80 | 4|■■■■ |
81 - 85 | 6|■■■■■■ |
86 - 90 | 8|■■■■■■■■ |
91 - 95 | 7|■■■■■■■ |
96 - 100| 18|■■■■■■■■■■■■■■■■■■|
sphinxcontrib.datatemplates ¶
sphinxcontrib.datatemplates is a Sphinx extension for rendering nicely formatted HTML with parts of the output coming from JSON and YAML data files.
It is intended to be used to mix machine-readable data with prose.