API Documentation
datajudge allows to assess whether data from database complies with referenceinformation.
BetweenRequirement
BetweenRequirement(data_source: DataSource, data_source2: DataSource, date_column: str | None = None, date_column2: str | None = None)
Bases: Requirement
Source code in src/datajudge/requirements.py
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 | |
add_column_subset_constraint
add_column_subset_constraint(name: str | None = None, cache_size=None) -> None
Columns of first table are subset of second table.
Source code in src/datajudge/requirements.py
2008 2009 2010 2011 2012 2013 2014 2015 2016 | |
add_column_superset_constraint
add_column_superset_constraint(name: str | None = None, cache_size=None) -> None
Columns of first table are superset of columns of second table.
Source code in src/datajudge/requirements.py
2018 2019 2020 2021 2022 2023 2024 2025 2026 | |
add_column_type_constraint
add_column_type_constraint(column1: str, column2: str, name: str | None = None, cache_size=None) -> None
Check that the columns have the same type.
Source code in src/datajudge/requirements.py
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 | |
add_date_max_constraint
add_date_max_constraint(column1: str, column2: str, use_upper_bound_reference: bool = True, column_type: str = 'date', condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Compare date max of first table to date max of second table.
The used columns of both tables need to be of the same type.
For more information on column_type values, see add_column_type_constraint.
If use_upper_bound_reference, the max of the first table has to be
smaller or equal to the max of the second table.
If not use_upper_bound_reference, the max of the first table has to
be greater or equal to the max of the second table.
Source code in src/datajudge/requirements.py
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 | |
add_date_min_constraint
add_date_min_constraint(column1: str, column2: str, use_lower_bound_reference: bool = True, column_type: str = 'date', condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure date min of first table is greater or equal date min of second table.
The used columns of both tables need to be of the same type.
For more information on column_type values, see add_column_type_constraint.
If use_lower_bound_reference, the min of the first table has to be
greater or equal to the min of the second table.
If not use_upper_bound_reference, the min of the first table has to
be smaller or equal to the min of the second table.
Source code in src/datajudge/requirements.py
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 | |
add_ks_2sample_constraint
add_ks_2sample_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, significance_level: float = 0.05, cache_size=None) -> None
Apply the so-called two-sample Kolmogorov-Smirnov test to the distributions of the two given columns.
The constraint is fulfilled, when the resulting p-value of the test is higher than the significance level (default is 0.05, i.e., 5%). The significance_level must be a value between 0.0 and 1.0.
Source code in src/datajudge/requirements.py
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 | |
add_max_null_fraction_constraint
add_max_null_fraction_constraint(column1: str, column2: str, max_relative_deviation: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the fraction of NULL values of one is at most that of the other.
Given that column2's underlying data has a fraction q of NULL values, the
max_relative_deviation parameter allows column1's underlying data to have a
fraction (1 + max_relative_deviation) * q of NULL values.
Source code in src/datajudge/requirements.py
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
add_n_rows_equality_constraint
add_n_rows_equality_constraint(condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 | |
add_n_rows_max_gain_constraint
add_n_rows_max_gain_constraint(constant_max_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't grown by more than expected.
In particular, assert that
See readme for more information on constant_max_relative_gain.
Source code in src/datajudge/requirements.py
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | |
add_n_rows_max_loss_constraint
add_n_rows_max_loss_constraint(constant_max_relative_loss: float | None = None, date_range_loss_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't decreased too much.
In particular, assert that
See readme for more information on constant_max_relative_loss.
Source code in src/datajudge/requirements.py
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 | |
add_n_rows_min_gain_constraint
add_n_rows_min_gain_constraint(constant_min_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't grown less than expected.
In particular, assert that
See readme for more information on constant_min_relative_gain.
Source code in src/datajudge/requirements.py
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 | |
add_n_uniques_equality_constraint
add_n_uniques_equality_constraint(columns1: list[str] | None, columns2: list[str] | None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | |
add_n_uniques_max_gain_constraint
add_n_uniques_max_gain_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of uniques hasn't grown by too much.
In particular, assert that
The number of uniques in first table are defined based on columns1, the
number of uniques in second table are defined based on columns2.
See readme for more information on constant_max_relative_gain.
Source code in src/datajudge/requirements.py
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | |
add_n_uniques_max_loss_constraint
add_n_uniques_max_loss_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_relative_loss: float | None = None, date_range_loss_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of uniques hasn't decreased too much.
In particular, assert that
The number of uniques in first table are defined based on columns1, the
number of uniques in second table are defined based on columns2.
See readme for more information on constant_max_relative_loss.
Source code in src/datajudge/requirements.py
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
add_numeric_max_constraint
add_numeric_max_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 | |
add_numeric_mean_constraint
add_numeric_mean_constraint(column1: str, column2: str, max_absolute_deviation: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 | |
add_numeric_min_constraint
add_numeric_min_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 | |
add_numeric_percentile_constraint
add_numeric_percentile_constraint(column1: str, column2: str, percentage: float, max_absolute_deviation: float | None = None, max_relative_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the percentage-th percentile is approximately equal.
The percentile is defined as the smallest value present in column1 / column2
for which percentage % of the values in column1 / column2 are
less or equal. NULL values are ignored.
Hence, if percentage is less than the inverse of the number of non-NULL
rows, None is received as the percentage-th percentile.
percentage is expected to be provided in percent. The median, for example,
would correspond to percentage=50.
At least one of max_absolute_deviation and max_relative_deviation must
be provided.
Source code in src/datajudge/requirements.py
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 | |
add_row_equality_constraint
add_row_equality_constraint(columns1: list[str] | None, columns2: list[str] | None, max_missing_fraction: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T1 and T2 are absent in either.
In other words
Rows from T1 are indexed in columns1, rows from T2 are indexed in columns2.
Source code in src/datajudge/requirements.py
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 | |
add_row_matching_equality_constraint
add_row_matching_equality_constraint(matching_columns1: list[str], matching_columns2: list[str], comparison_columns1: list[str], comparison_columns2: list[str], max_missing_fraction: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Match tables in matching_columns, compare for equality in comparison_columns.
This constraint is similar to the nature of the RowEquality
constraint. Just as the latter, this constraint divides the
cardinality of an intersection by the cardinality of a union.
The difference lies in how the set are created. While RowEquality
considers all rows of both tables, indexed in columns,
RowMatchingEquality considers only rows in both tables having values
in matching_columns present in both tables. At most max_missing_fraction
of such rows can be missing in the intersection.
Alternatively, this can be thought of as counting mismatches in
comparison_columns after performing an inner join on matching_columns.
Source code in src/datajudge/requirements.py
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 | |
add_row_subset_constraint
add_row_subset_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_missing_fraction: float | None, date_range_loss_fraction: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T1 are not in T2.
In other words,
:math:\frac{|T1-T2|}{|T1|} \leq max_missing_fraction.
Rows from T1 are indexed in columns1, rows from T2 are indexed in columns2.
In particular, the operation |T1-T2| relies on a sql EXCEPT statement. In
contrast to EXCEPT ALL, this should lead to a set subtraction instead of
a multiset subtraction. In other words, duplicates in T1 are treated as
single occurrences.
Source code in src/datajudge/requirements.py
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 | |
add_row_superset_constraint
add_row_superset_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_missing_fraction: float, date_range_loss_fraction: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T2 are not in T1.
In other words, \(\frac{|T2-T1|}{|T2|} \leq\) max_missing_fraction.
Rows from T1 are indexed in columns1, rows from T2 are indexed in
columns2.
Source code in src/datajudge/requirements.py
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 | |
add_uniques_equality_constraint
add_uniques_equality_constraint(columns1: list[str], columns2: list[str], filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Check if the data's unique values in given columns are equal.
The UniquesEquality constraint asserts if the values contained in a column
of a DataSource's columns, are strictly the ones of another DataSource's
columns.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly..
See Uniques for further parameter details on map_func,
reduce_func, and output_processors.
Source code in src/datajudge/requirements.py
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 | |
add_uniques_subset_constraint
add_uniques_subset_constraint(columns1: list[str], columns2: list[str], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, compare_distinct: bool = False, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None) -> None
Check if the given columns's unique values in are contained in reference data.
The UniquesSubset constraint asserts if the values contained in given column of
a DataSource are part of the unique values of given columns of another
DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of rows of the given table
may have values not included in the reference set of unique values. Please note
that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
By default, the number of occurrences affects the computed fraction of violations.
To disable this weighting, set compare_distinct=True.
This argument does not have an effect on the test results for other Uniques constraints,
or if max_relative_violations is 0.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 | |
add_uniques_superset_constraint
add_uniques_superset_constraint(columns1: list[str], columns2: list[str], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None) -> None
Check if unique values of columns are contained in the reference data.
The UniquesSuperset constraint asserts that reference set of expected values,
derived from the unique values in given columns of the reference DataSource,
is contained in given columns of a DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly..
max_relative_violations indicates what fraction of unique values of the given
DataSource are not represented in the reference set of unique values. Please
note that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
One use of this constraint is to test for consistency in columns with expected categorical values.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 | |
add_varchar_max_length_constraint
add_varchar_max_length_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 | |
add_varchar_min_length_constraint
add_varchar_min_length_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 | |
from_expressions
classmethod
from_expressions(expression1, expression2, name1: str, name2: str, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenTableRequirement based on sqlalchemy expressions.
Any sqlalchemy object implementing the alias method can be passed as an
argument for the expression1 and expression2 parameters. This could,
e.g. be a sqlalchemy.Table object or the result of a sqlalchemy.select
invocation.
name1 and name2 will be used to represent the expressions in error messages,
respectively.
Source code in src/datajudge/requirements.py
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | |
from_raw_queries
classmethod
from_raw_queries(query1: str, query2: str, name1: str, name2: str, columns1: list[str] | None = None, columns2: list[str] | None = None, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenRequirement based on raw query strings.
The query1 and query2 parameters can be passed any query string returning
rows, e.g. "SELECT * FROM myschema.mytable LIMIT 1337" or
"SELECT id, name FROM table1 UNION SELECT id, name FROM table2".
name1 and name2 will be used to represent the queries in error messages,
respectively.
If constraints rely on specific columns, these should be provided here via
columns1 and columns2 respectively.
Source code in src/datajudge/requirements.py
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 | |
from_tables
classmethod
from_tables(db_name1: str, schema_name1: str, table_name1: str, db_name2: str, schema_name2: str, table_name2: str, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenRequirement based on a table.
Source code in src/datajudge/requirements.py
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
Condition
dataclass
Condition(raw_string: str | None = None, conditions: Sequence[Condition] | None = None, reduction_operator: str | None = None)
Condition allows for further narrowing down of a DataSource in a Constraint.
A Condition can be thought of as a filter, the content of a sql 'where' clause
or a condition as known from probability theory.
While a DataSource is expressed more generally, one might be interested
in testing properties of a specific part of said DataSource in light
of a particular constraint. Hence using Condition allows for the reusage
of a DataSource, in lieu of creating a new custom DataSource with
the Condition implicitly built in.
A Condition can either be 'atomic', i.e. not further reducible to sub-conditions
or 'composite', i.e. combining multiple subconditions. In the former case, it can
be instantiated with help of the raw_string parameter, e.g. "col1 > 0". In the
latter case, it can be instantiated with help of the conditions and
reduction_operator parameters. reduction_operator allows for two values: "and" (logical
conjunction) and "or" (logical disjunction). Note that composition of Condition
supports arbitrary degrees of nesting.
conditions
class-attribute
instance-attribute
conditions: Sequence[Condition] | None = None
raw_string
class-attribute
instance-attribute
raw_string: str | None = None
reduction_operator
class-attribute
instance-attribute
reduction_operator: str | None = None
Constraint
Constraint(ref: DataReference, *, ref2: DataReference | None = None, ref_value: Any = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Bases: ABC
Express a DataReference constraint against either another DataReference or a reference value.
Constraints against other DataReferences are typically referred to as 'between' constraints.
Please use the the ref2 argument to instantiate such a constraint.
Constraints against a fixed reference value are typically referred to as 'within' constraints.
Please use the ref_value argument to instantiate such a constraint.
A constraint typically relies on the comparison of factual and target values. The former
represent the key quantity of interest as seen in the database, the latter the key quantity of
interest as expected a priori. Such a comparison is meant to be carried out in the test
method.
In order to obtain such values, the retrieve method defines a mapping from DataReference,
be it the DataReference of primary interest, ref, or a baseline DataReference, ref2, to
value. If ref_value is already provided, usually no further mapping needs to be taken care of.
By default, retrieved arguments are cached indefinitely @lru_cache(maxsize=None).
This can be controlled by setting the cache_size argument to a different value.
0 disables caching.
Source code in src/datajudge/constraints/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
name
instance-attribute
name = name
get_description
get_description() -> str
Source code in src/datajudge/constraints/base.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/base.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
DataSource
Bases: ABC
Requirement
Requirement()
Bases: ABC, MutableSequence
Source code in src/datajudge/requirements.py
63 64 65 | |
insert
insert(index: int, value: Constraint) -> None
Source code in src/datajudge/requirements.py
67 68 | |
test
test(engine) -> list[TestResult]
Source code in src/datajudge/requirements.py
82 83 | |
WithinRequirement
WithinRequirement(data_source: DataSource)
Bases: Requirement
Source code in src/datajudge/requirements.py
87 88 89 | |
add_categorical_bound_constraint
add_categorical_bound_constraint(columns: list[str], distribution: dict[_T, tuple[float, float]], default_bounds: tuple[float, float] = (0, 0), max_relative_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Check if the distribution of unique values in columns falls within the specified minimum and maximum bounds.
The CategoricalBoundConstraint is added to ensure the distribution of unique values
in the specified columns of a DataSource falls within the given minimum and maximum
bounds defined in the distribution parameter.
| PARAMETER | DESCRIPTION |
|---|---|
columns
|
A list of column names from the
TYPE:
|
distribution
|
A dictionary where keys represent unique values and the corresponding tuple values represent the minimum and maximum allowed proportions of the respective unique value in the columns.
TYPE:
|
default_bounds
|
A tuple specifying the minimum and maximum allowed proportions for all
elements not mentioned in the distribution. By default, it's set to (0, 0), which means
all elements not present in
TYPE:
|
max_relative_violations
|
A tolerance threshold (0 to 1) for the proportion of elements in the data that can violate the bound constraints without triggering the constraint violation.
TYPE:
|
condition
|
An optional parameter to specify a
TYPE:
|
name
|
An optional parameter to provide a custom name for the constraint.
TYPE:
|
cache_size
|
TODO
DEFAULT:
|
Example:
This method can be used to test for consistency in columns with expected categorical values or ensure that the distribution of values in a column adheres to a certain criterion.
Usage:
requirement = WithinRequirement(data_source)
requirement.add_categorical_bound_constraint(
columns=['column_name'],
distribution={'A': (0.2, 0.3), 'B': (0.4, 0.6), 'C': (0.1, 0.2)},
max_relative_violations=0.05,
name='custom_name'
)
Source code in src/datajudge/requirements.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
add_column_existence_constraint
add_column_existence_constraint(columns: list[str], name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
127 128 129 130 131 132 133 134 | |
add_column_type_constraint
add_column_type_constraint(column: str, column_type: str | TypeEngine, name: str | None = None, cache_size=None) -> None
Check if a column type matches the expected column_type.
The column_type can be provided as a string (backend-specific type name), a backend-specific SQLAlchemy type, or a SQLAlchemy's generic type.
If SQLAlchemy's generic types are used, the check is performed using isinstance, which means that the actual type can also be a subclass of the target type.
For more information on SQLAlchemy's generic types, see https://docs.sqlalchemy.org/en/20/core/type_basics.html
| PARAMETER | DESCRIPTION |
|---|---|
column
|
The name of the column to which the constraint will be applied.
TYPE:
|
column_type
|
The expected type of the column. This can be a string, a backend-specific SQLAlchemy type, or a generic SQLAlchemy type.
TYPE:
|
name
|
An optional name for the constraint. If not provided, a name will be generated automatically.
TYPE:
|
Source code in src/datajudge/requirements.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
add_date_between_constraint
add_date_between_constraint(column: str, lower_bound: str, upper_bound: str, min_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Use string format: lower_bound="'20121230'".
Source code in src/datajudge/requirements.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
add_date_max_constraint
add_date_max_constraint(column: str, max_value: str, use_upper_bound_reference: bool = True, column_type: str = 'date', condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure all dates to be superior than max_value.
Use string format: max_value="'20121230'"
For more information on column_type values, see add_column_type_constraint.
If use_upper_bound_reference is True, the maximum date in column has to be smaller or
equal to max_value. Otherwise the maximum date in column has to be greater or equal
to max_value.
Source code in src/datajudge/requirements.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
add_date_min_constraint
add_date_min_constraint(column: str, min_value: str, use_lower_bound_reference: bool = True, column_type: str = 'date', condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure all dates to be superior than min_value.
Use string format: min_value="'20121230'".
For more information on column_type values, see add_column_type_constraint.
If use_lower_bound_reference, the min of the first table has to be
greater or equal to min_value.
If not use_upper_bound_reference, the min of the first table has to
be smaller or equal to min_value.
Source code in src/datajudge/requirements.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
add_date_no_gap_constraint
add_date_no_gap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Express that date range rows have no gap in-between them.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Additionally, a start_column and an end_column,
indicating start and end dates, should be provided.
Neither of those columns should contain NULL values. Also, it should hold that
for a given row, the value of end_column is strictly greater than the value of
start_column.
Note that the value of start_column is expected to be included in each date range.
By default, the value of end_column is expected to be included as well - this can
however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often has
several rows. Thereby, a key will often come with several date ranges.
If key_columns is None or [], all columns of the table will be
considered as composing the key.
In order to express a tolerance for some violations of this gap property, use the
max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one gap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
add_date_no_overlap_2d_constraint
add_date_no_overlap_2d_constraint(start_column1: str, end_column1: str, start_column2: str, end_column2: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Express that several date range rows do not overlap in two date dimensions.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Per date dimension, a start column (start_column1, start_column2)
and end (end_column1, end_column2) column should be provided in order to define
date ranges.
Date ranges in different date dimensions are expected to represent different kinds
of dates. For example, let's say that a row in a table indicates an averag temperature
forecast. start_column1 and end_column1 could the date span that was forecasted,
e.g. the weather from next Saturday to next Sunday. end_column1 and end_column2
might indicate the timespan when this forceast was used, e.g. from the
previous Monday to Wednesday.
Neither of those columns should contain NULL values. Also, the value of end_column_k
should be strictly greater than the value of start_column_k.
Note that the values of start_column1 and start_column2 are expected to be
included in each date range. By default, the values of end_column1 and
end_column2 are expected to be included as well - this can however be changed
by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of interest. A priori, a key is not a primary key, i.e., a key can have and often has several rows. Thereby, a key will often come with several date ranges.
Often, you might want the date ranges for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered as
composing the key.
In order to express a tolerance for some violations of this non-overlapping property,
use the max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
add_date_no_overlap_constraint
add_date_no_overlap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Constraint expressing that several date range rows may not overlap.
The DataSource under inspection must consist of at least one but up
to many key_columns, identifying an entity, a start_column and an
end_column.
For a given row in this DataSource, start_column and end_column indicate a
date range. Neither of those columns should contain NULL values. Also, it
should hold that for a given row, the value of end_column is strictly greater
than the value of start_column.
Note that the value of start_column is expected to be included in each date
range. By default, the value of end_column is expected to be included as well -
this can however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often
has several rows. Thereby, a key will often come with several date ranges.
Often, you might want the date ranges for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered
as composing the key.
In order to express a tolerance for some violations of this non-overlapping
property, use the max_relative_n_violations parameter. The latter expresses for
what fraction of all key values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
add_functional_dependency_constraint
add_functional_dependency_constraint(key_columns: list[str], value_columns: list[str], condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Expresses a functional dependency, a constraint where the value_columns are uniquely determined by the key_columns.
This means that for each unique combination of values in the key_columns, there is exactly one corresponding combination of values in the value_columns.
The add_unique_constraint constraint is a special case of this constraint, where the key_columns are a primary key,
and all other columns are included value_columns.
This constraint allows for a more general definition of functional dependencies, where the key_columns are not necessarily a primary key.
An additional configuration option (for details see the analogous parameter in for Uniques-constraints)
on how the output is sorted and how many counterexamples are shown is available as output_processors.
An additional configuration option (for details see the analogous parameter in for Uniques-constraints)
on how the output is sorted and how many counterexamples are shown is available as output_processors.
For more information on functional dependencies, see https://en.wikipedia.org/wiki/Functional_dependency.
Source code in src/datajudge/requirements.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
add_groupby_aggregation_constraint
add_groupby_aggregation_constraint(columns: Sequence[str], aggregation_column: str, start_value: int, tolerance: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Check whether array aggregate corresponds to an integer range.
The DataSource is grouped by columns. Sql's array_agg function is then
applied to the aggregate_column.
Since we expect aggregate_column to be a numeric column, this leads to
a multiset of aggregated values. These values should correspond to the integers
ranging from start_value to the cardinality of the multiset.
In order to allow for slight deviations from this pattern, tolerance expresses
the fraction of all grouped-by rows, which may be incomplete ranges.
Source code in src/datajudge/requirements.py
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 | |
add_max_null_fraction_constraint
add_max_null_fraction_constraint(column: str, max_null_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None)
Assert that column has less than a certain fraction of NULL values.
max_null_fraction is expected to lie within [0, 1].
Source code in src/datajudge/requirements.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
add_n_rows_equality_constraint
add_n_rows_equality_constraint(n_rows: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
259 260 261 262 263 264 265 266 267 268 269 270 271 | |
add_n_rows_max_constraint
add_n_rows_max_constraint(n_rows_max: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
287 288 289 290 291 292 293 294 295 296 297 298 299 | |
add_n_rows_min_constraint
add_n_rows_min_constraint(n_rows_min: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
273 274 275 276 277 278 279 280 281 282 283 284 285 | |
add_n_uniques_equality_constraint
add_n_uniques_equality_constraint(columns: list[str] | None, n_uniques: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
add_null_absence_constraint
add_null_absence_constraint(column: str, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
223 224 225 226 227 228 229 230 231 232 233 234 235 | |
add_numeric_between_constraint
add_numeric_between_constraint(column: str, lower_bound: float, upper_bound: float, min_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the column's values lie between lower_bound and upper_bound.
Note that both bounds are inclusive.
Unless specified otherwise via the usage of a condition, NULL values will
be considered in the denominator of min_fraction. NULL values will never be
considered to lie in the interval [lower_bound, upper_bound].
Source code in src/datajudge/requirements.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
add_numeric_max_constraint
add_numeric_max_constraint(column: str, max_value: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
All values in column are less or equal max_value.
Source code in src/datajudge/requirements.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
add_numeric_mean_constraint
add_numeric_mean_constraint(column: str, mean_value: float, max_absolute_deviation: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert the mean of the column column deviates at most max_deviation from mean_value.
Source code in src/datajudge/requirements.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
add_numeric_min_constraint
add_numeric_min_constraint(column: str, min_value: float, condition: Condition | None = None, cache_size=None) -> None
All values in column are greater or equal min_value.
Source code in src/datajudge/requirements.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
add_numeric_no_gap_constraint
add_numeric_no_gap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, legitimate_gap_size: float = 0, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Express that numeric interval rows have no gaps larger than some max value in-between them.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Additionally, a start_column and an end_column,
indicating interval start and end values, should be provided.
Neither of those columns should contain NULL values. Also, it should hold that
for a given row, the value of end_column is strictly greater than the value of
start_column.
legitimate_gap_size is the maximum tollerated gap size between two intervals.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often has
several rows. Thereby, a key will often come with several intervals.
If key_columns is None or [], all columns of the table will be
considered as composing the key.
In order to express a tolerance for some violations of this gap property, use the
max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one gap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | |
add_numeric_no_overlap_constraint
add_numeric_no_overlap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Constraint expressing that several numeric interval rows may not overlap.
The DataSource under inspection must consist of at least one but up
to many key_columns, identifying an entity, a start_column and an
end_column.
For a given row in this DataSource, start_column and end_column indicate a
numeric interval. Neither of those columns should contain NULL values. Also, it
should hold that for a given row, the value of end_column is strictly greater
than the value of start_column.
Note that the value of start_column is expected to be included in each interval.
By default, the value of end_column is expected to be included as well -
this can however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often
has several rows. Thereby, a key will often come with several intervals.
Often, you might want the intervals for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered
as composing the key.
In order to express a tolerance for some violations of this non-overlapping
property, use the max_relative_n_violations parameter. The latter expresses for
what fraction of all key values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 | |
add_numeric_percentile_constraint
add_numeric_percentile_constraint(column: str, percentage: float, expected_percentile: float, max_absolute_deviation: float | None = None, max_relative_deviation: float | None = None, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the percentage-th percentile is approximately expected_percentile.
The percentile is defined as the smallest value present in column for which
percentage % of the values in column are less or equal. NULL values
are ignored.
Hence, if percentage is less than the inverse of the number of non-NULL rows,
None is received as the percentage -th percentile.
percentage is expected to be provided in percent. The median, for example, would
correspond to percentage=50.
At least one of max_absolute_deviation and max_relative_deviation must
be provided.
Source code in src/datajudge/requirements.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
add_primary_key_definition_constraint
add_primary_key_definition_constraint(primary_keys: list[str], name: str | None = None, cache_size=None) -> None
Check that the primary key constraints in the database are exactly equal to the given column names.
Note that this doesn't actually check that the primary key values are unique across the table.
Source code in src/datajudge/requirements.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
add_uniqueness_constraint
add_uniqueness_constraint(columns: list[str] | None = None, max_duplicate_fraction: float = 0, condition: Condition | None = None, max_absolute_n_duplicates: int = 0, infer_pk_columns: bool = False, name: str | None = None, cache_size=None) -> None
Columns should uniquely identify row.
Given a list of columns columns, validate the condition of a primary key, i.e.
uniqueness of tuples in said columns. This constraint has a tolerance
for inconsistencies, expressed via max_duplicate_fraction. The latter
suggests that the number of uniques from said columns is larger or equal
to 1 - max_duplicate_fraction times the number of rows.
If infer_pk_columns is True, columns will be retrieved from the primary keys.
If columns is None and infer_pk_column is False, the fallback is
validating that all rows in a table are unique.
Source code in src/datajudge/requirements.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
add_uniques_equality_constraint
add_uniques_equality_constraint(columns: list[str], uniques: Collection[_T], filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, condition: Condition | None = None, name: str | None = None, cache_size=None)
Check if the data's unique values are equal to a given set of values.
The UniquesEquality constraint asserts if the values contained in a column
of a DataSource are strictly the ones of a reference set of expected values,
specified via the uniques parameter.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
See the Uniques class for further parameter details on map_func and
reduce_func, and output_processors.
Source code in src/datajudge/requirements.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
add_uniques_subset_constraint
add_uniques_subset_constraint(columns: list[str], uniques: Collection[_T], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, compare_distinct: bool = False, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Check if the data's unique values are contained in a given set of values.
The UniquesSubset constraint asserts if the values contained in a column of
a DataSource are part of a reference set of expected values, specified via
uniques.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of rows of the given table
may have values not included in the reference set of unique values. Please note
that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
By default, the number of occurrences affects the computed fraction of violations.
To disable this weighting, set compare_distinct=True.
This argument does not have an effect on the test results for other Uniques constraints,
or if max_relative_violations is 0.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
add_uniques_superset_constraint
add_uniques_superset_constraint(columns: list[str], uniques: Collection[_T], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Check if unique values of columns are contained in the reference data.
The UniquesSuperset constraint asserts that reference set of expected values,
specified via uniques, is contained in given columns of a DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
will cause (possibly often unintended) changes in behavior when the user adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of unique values of the given
DataSource are not represented in the reference set of unique values. Please
note that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
One use of this constraint is to test for consistency in columns with expected categorical values.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
add_varchar_max_length_constraint
add_varchar_max_length_constraint(column: str, max_length: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
add_varchar_min_length_constraint
add_varchar_min_length_constraint(column: str, min_length: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
add_varchar_regex_constraint
add_varchar_regex_constraint(column: str, regex: str, condition: Condition | None = None, name: str | None = None, allow_none: bool = False, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, cache_size=None)
Assesses whether the values in a column match a given regular expression pattern.
The option allow_none can be used in cases where the column is defined as
nullable and contains null values.
How the tolerance factor is calculated can be controlled with the aggregated
flag. When True, the tolerance is calculated using unique values. If not, the
tolerance is calculated using all the instances of the data.
n_counterexamples defines how many counterexamples are displayed in an
assertion text. If all counterexamples are meant to be shown, provide -1 as
an argument.
When using this method, the regex matching will take place in memory. If instead,
you would like the matching to take place in database which is typically faster and
substantially more memory-saving, please consider using
add_varchar_regex_constraint_db.
Source code in src/datajudge/requirements.py
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
add_varchar_regex_constraint_db
add_varchar_regex_constraint_db(column: str, regex: str, condition: Condition | None = None, name: str | None = None, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, cache_size=None)
Assesses whether the values in a column match a given regular expression pattern.
How the tolerance factor is calculated can be controlled with the aggregated
flag. When True, the tolerance is calculated using unique values. If not, the
tolerance is calculated using all the instances of the data.
n_counterexamples defines how many counterexamples are displayed in an
assertion text. If all counterexamples are meant to be shown, provide -1 as
an argument.
When using this method, the regex matching will take place in database, which is
only supported for Postgres, Sqllite and Snowflake. Note that for this
feature is only for Snowflake when using sqlalchemy-snowflake >= 1.4.0. As an
alternative, add_varchar_regex_constraint performs the regex matching in memory.
This is typically slower and more expensive in terms of memory but available
on all supported database mamangement systems.
Source code in src/datajudge/requirements.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | |
from_expression
classmethod
from_expression(expression: FromClause, name: str)
Create a WithinRequirement based on a sqlalchemy expression.
Any sqlalchemy object implementing the alias method can be passed as an
argument for the expression parameter. This could, e.g. be an
sqlalchemy.Table object or the result of a sqlalchemy.select call.
The name will be used to represent this expression in error messages.
Source code in src/datajudge/requirements.py
115 116 117 118 119 120 121 122 123 124 125 | |
from_raw_query
classmethod
from_raw_query(query: str, name: str, columns: list[str] | None = None)
Create a WithinRequirement based on a raw query string.
The query parameter can be passed any query string returning rows, e.g.
"SELECT * FROM myschema.mytable LIMIT 1337" or
"SELECT id, name FROM table1 UNION SELECT id, name FROM table2".
The name will be used to represent this query in error messages.
If constraints rely on specific columns, these should be provided here via
columns, e.g. ["id", "name"].
Source code in src/datajudge/requirements.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
from_table
classmethod
from_table(db_name: str, schema_name: str, table_name: str)
Create a WithinRequirement based on a table.
Source code in src/datajudge/requirements.py
91 92 93 94 95 96 97 98 | |
condition
Condition
dataclass
Condition(raw_string: str | None = None, conditions: Sequence[Condition] | None = None, reduction_operator: str | None = None)
Condition allows for further narrowing down of a DataSource in a Constraint.
A Condition can be thought of as a filter, the content of a sql 'where' clause
or a condition as known from probability theory.
While a DataSource is expressed more generally, one might be interested
in testing properties of a specific part of said DataSource in light
of a particular constraint. Hence using Condition allows for the reusage
of a DataSource, in lieu of creating a new custom DataSource with
the Condition implicitly built in.
A Condition can either be 'atomic', i.e. not further reducible to sub-conditions
or 'composite', i.e. combining multiple subconditions. In the former case, it can
be instantiated with help of the raw_string parameter, e.g. "col1 > 0". In the
latter case, it can be instantiated with help of the conditions and
reduction_operator parameters. reduction_operator allows for two values: "and" (logical
conjunction) and "or" (logical disjunction). Note that composition of Condition
supports arbitrary degrees of nesting.
conditions
class-attribute
instance-attribute
conditions: Sequence[Condition] | None = None
raw_string
class-attribute
instance-attribute
raw_string: str | None = None
reduction_operator
class-attribute
instance-attribute
reduction_operator: str | None = None
constraints
base
Constraint
Constraint(ref: DataReference, *, ref2: DataReference | None = None, ref_value: Any = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Bases: ABC
Express a DataReference constraint against either another DataReference or a reference value.
Constraints against other DataReferences are typically referred to as 'between' constraints.
Please use the the ref2 argument to instantiate such a constraint.
Constraints against a fixed reference value are typically referred to as 'within' constraints.
Please use the ref_value argument to instantiate such a constraint.
A constraint typically relies on the comparison of factual and target values. The former
represent the key quantity of interest as seen in the database, the latter the key quantity of
interest as expected a priori. Such a comparison is meant to be carried out in the test
method.
In order to obtain such values, the retrieve method defines a mapping from DataReference,
be it the DataReference of primary interest, ref, or a baseline DataReference, ref2, to
value. If ref_value is already provided, usually no further mapping needs to be taken care of.
By default, retrieved arguments are cached indefinitely @lru_cache(maxsize=None).
This can be controlled by setting the cache_size argument to a different value.
0 disables caching.
Source code in src/datajudge/constraints/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
name
instance-attribute
name = name
get_description
get_description() -> str
Source code in src/datajudge/constraints/base.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/base.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
TestResult
dataclass
TestResult(outcome: bool, _failure_message: str | None = None, _constraint_description: str | None = None, _factual_queries: str | None = None, _target_queries: str | None = None)
The result of the execution of a Constraint.
constraint_description
property
constraint_description: str | None
failure_message
property
failure_message: str | None
logging_message
property
logging_message
outcome
instance-attribute
outcome: bool
failure
classmethod
failure(*args, **kwargs)
Source code in src/datajudge/constraints/base.py
99 100 101 | |
formatted_constraint_description
formatted_constraint_description(formatter: Formatter) -> str | None
Source code in src/datajudge/constraints/base.py
48 49 50 51 52 53 | |
formatted_failure_message
formatted_failure_message(formatter: Formatter) -> str | None
Source code in src/datajudge/constraints/base.py
43 44 45 46 | |
success
classmethod
success()
Source code in src/datajudge/constraints/base.py
95 96 97 | |
column
Column
Column(ref: DataReference, *, ref2: DataReference | None = None, ref_value: Any = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Bases: Constraint, ABC
Source code in src/datajudge/constraints/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
ColumnExistence
ColumnExistence(ref: DataReference, columns: list[str], name: str | None = None, cache_size=None)
Bases: Column
Source code in src/datajudge/constraints/column.py
25 26 27 28 29 30 31 32 | |
ColumnSubset
ColumnSubset(ref: DataReference, *, ref2: DataReference | None = None, ref_value: Any = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Bases: Column
Source code in src/datajudge/constraints/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
ColumnSuperset
ColumnSuperset(ref: DataReference, *, ref2: DataReference | None = None, ref_value: Any = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Bases: Column
Source code in src/datajudge/constraints/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
ColumnType
ColumnType(ref: DataReference, *, ref2: DataReference | None = None, column_type: str | TypeEngine | None = None, name: str | None = None, cache_size=None)
Bases: Constraint
A class used to represent a ColumnType constraint.
This class enables flexible specification of column types either in string format or using SQLAlchemy's type hierarchy. It checks whether a column's type matches the specified type, allowing for checks against backend-specific types, SQLAlchemy's generic types, or string representations of backend-specific types.
When using SQLAlchemy's generic types, the comparison is done using isinstance, which means that the actual type can also be a subclass of the target type.
For more information, see https://docs.sqlalchemy.org/en/20/core/type_basics.html
Source code in src/datajudge/constraints/column.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
date
Date
module-attribute
Date = str | date | datetime
DateBetween
DateBetween(ref: DataReference, min_fraction: float, lower_bound: str, upper_bound: str, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/date.py
149 150 151 152 153 154 155 156 157 158 159 160 | |
DateMax
DateMax(ref: DataReference, use_upper_bound_reference: bool, column_type: str, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, max_value: str | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/date.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
DateMin
DateMin(ref: DataReference, use_lower_bound_reference: bool, column_type: str, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, min_value: str | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/date.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
DateNoGap
DateNoGap(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, legitimate_gap_size: float, name: str | None = None, cache_size=None)
Bases: NoGapConstraint
Source code in src/datajudge/constraints/interval.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
select
select(engine: Engine, ref: DataReference)
Source code in src/datajudge/constraints/date.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
DateNoOverlap
DateNoOverlap(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, end_included: bool, name: str | None = None, cache_size=None)
Bases: NoOverlapConstraint
Source code in src/datajudge/constraints/interval.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
DateNoOverlap2d
DateNoOverlap2d(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, end_included: bool, name: str | None = None, cache_size=None)
Bases: NoOverlapConstraint
Source code in src/datajudge/constraints/interval.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
groupby
AggregateNumericRangeEquality
AggregateNumericRangeEquality(ref: DataReference, aggregation_column: str, start_value: int = 0, name: str | None = None, cache_size=None, *, tolerance: float = 0, ref2: DataReference | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/groupby.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
interval
IntervalConstraint
IntervalConstraint(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/interval.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
select
abstractmethod
select(engine: Engine, ref: DataReference)
Source code in src/datajudge/constraints/interval.py
33 34 35 | |
NoGapConstraint
NoGapConstraint(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, legitimate_gap_size: float, name: str | None = None, cache_size=None)
Bases: IntervalConstraint
Source code in src/datajudge/constraints/interval.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
select
abstractmethod
select(engine: Engine, ref: DataReference)
Source code in src/datajudge/constraints/interval.py
136 137 138 | |
NoOverlapConstraint
NoOverlapConstraint(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, end_included: bool, name: str | None = None, cache_size=None)
Bases: IntervalConstraint
Source code in src/datajudge/constraints/interval.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
select
select(engine: Engine, ref: DataReference)
Source code in src/datajudge/constraints/interval.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
miscs
FunctionalDependency
FunctionalDependency(ref: DataReference, key_columns: list[str], **kwargs)
Bases: Constraint
Source code in src/datajudge/constraints/miscs.py
127 128 129 | |
key_columns
instance-attribute
key_columns = key_columns
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/miscs.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
MaxNullFraction
MaxNullFraction(ref, *, ref2: DataReference | None = None, max_null_fraction: float | None = None, max_relative_deviation: float = 0, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/miscs.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
max_relative_deviation
instance-attribute
max_relative_deviation = max_relative_deviation
PrimaryKeyDefinition
PrimaryKeyDefinition(ref, primary_keys: list[str], name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/miscs.py
13 14 15 16 17 18 19 20 | |
Uniqueness
Uniqueness(ref: DataReference, max_duplicate_fraction: float = 0, max_absolute_n_duplicates: int = 0, infer_pk_columns: bool = False, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/miscs.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
infer_pk_columns
instance-attribute
infer_pk_columns = infer_pk_columns
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/miscs.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
nrows
NRows
NRows(ref: DataReference, *, ref2: DataReference | None = None, n_rows: int | None = None, name: str | None = None, cache_size=None)
Bases: Constraint, ABC
Source code in src/datajudge/constraints/nrows.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
NRowsEquality
NRowsEquality(ref: DataReference, *, ref2: DataReference | None = None, n_rows: int | None = None, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
NRowsMax
NRowsMax(ref: DataReference, *, ref2: DataReference | None = None, n_rows: int | None = None, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
NRowsMaxGain
NRowsMaxGain(ref: DataReference, ref2: DataReference, max_relative_gain_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
124 125 126 127 128 129 130 131 132 133 | |
max_relative_gain_getter
instance-attribute
max_relative_gain_getter = max_relative_gain_getter
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/nrows.py
150 151 152 | |
NRowsMaxLoss
NRowsMaxLoss(ref: DataReference, ref2: DataReference, max_relative_loss_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
92 93 94 95 96 97 98 99 100 101 | |
max_relative_loss_getter
instance-attribute
max_relative_loss_getter = max_relative_loss_getter
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/nrows.py
118 119 120 | |
NRowsMin
NRowsMin(ref: DataReference, *, ref2: DataReference | None = None, n_rows: int | None = None, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
NRowsMinGain
NRowsMinGain(ref: DataReference, ref2: DataReference, min_relative_gain_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: NRows
Source code in src/datajudge/constraints/nrows.py
156 157 158 159 160 161 162 163 164 165 | |
min_relative_gain_getter
instance-attribute
min_relative_gain_getter = min_relative_gain_getter
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/nrows.py
182 183 184 | |
numeric
NumericBetween
NumericBetween(ref: DataReference, min_fraction: float, lower_bound: float, upper_bound: float, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/numeric.py
94 95 96 97 98 99 100 101 102 103 104 105 | |
NumericMax
NumericMax(ref: DataReference, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, max_value: float | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/numeric.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
NumericMean
NumericMean(ref: DataReference, max_absolute_deviation: float, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, mean_value: float | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/numeric.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/numeric.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
NumericMin
NumericMin(ref: DataReference, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, min_value: float | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/numeric.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
NumericNoGap
NumericNoGap(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, legitimate_gap_size: float, name: str | None = None, cache_size=None)
Bases: NoGapConstraint
Source code in src/datajudge/constraints/interval.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
select
select(engine: Engine, ref: DataReference)
Source code in src/datajudge/constraints/numeric.py
261 262 263 264 265 266 267 268 269 270 271 272 | |
NumericNoOverlap
NumericNoOverlap(ref: DataReference, key_columns: list[str] | None, start_columns: list[str], end_columns: list[str], max_relative_n_violations: float, end_included: bool, name: str | None = None, cache_size=None)
Bases: NoOverlapConstraint
Source code in src/datajudge/constraints/interval.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
NumericPercentile
NumericPercentile(ref: DataReference, percentage: float, max_absolute_deviation: float | None = None, max_relative_deviation: float | None = None, name: str | None = None, cache_size=None, *, ref2: DataReference | None = None, expected_percentile: float | None = None)
Bases: Constraint
Source code in src/datajudge/constraints/numeric.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
percentage
instance-attribute
percentage = percentage
row
Row
Row(ref: DataReference, ref2: DataReference, max_missing_fraction_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: Constraint, ABC
Source code in src/datajudge/constraints/row.py
14 15 16 17 18 19 20 21 22 23 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/row.py
25 26 27 28 29 30 31 32 33 34 35 | |
RowEquality
RowEquality(ref: DataReference, ref2: DataReference, max_missing_fraction_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: Row
Source code in src/datajudge/constraints/row.py
14 15 16 17 18 19 20 21 22 23 | |
RowMatchingEquality
RowMatchingEquality(ref: DataReference, ref2: DataReference, matching_columns1: list[str], matching_columns2: list[str], comparison_columns1: list[str], comparison_columns2: list[str], max_missing_fraction_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: Row
Source code in src/datajudge/constraints/row.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/row.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
RowSubset
RowSubset(ref: DataReference, ref2: DataReference, max_missing_fraction_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: Row
Source code in src/datajudge/constraints/row.py
14 15 16 17 18 19 20 21 22 23 | |
RowSuperset
RowSuperset(ref: DataReference, ref2: DataReference, max_missing_fraction_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: Row
Source code in src/datajudge/constraints/row.py
14 15 16 17 18 19 20 21 22 23 | |
stats
KolmogorovSmirnov2Sample
KolmogorovSmirnov2Sample(ref: DataReference, ref2: DataReference, significance_level: float = 0.05, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/stats.py
14 15 16 17 18 19 20 21 22 23 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/stats.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
uniques
CategoricalBoundConstraint
CategoricalBoundConstraint(ref: DataReference, distribution: dict[_T, tuple[float, float]], default_bounds: tuple[float, float] = (0, 0), name: str | None = None, cache_size=None, max_relative_violations: float = 0, **kwargs)
Bases: Constraint
Constraint that checks if the share of specific values in a column falls within predefined bounds.
It compares the actual distribution of values in a
DataSource column with a target distribution, supplied as a dictionary.
Example use cases include testing for consistency in columns with expected categorical values or ensuring that the distribution of values in a column adheres to a certain criterion.
| PARAMETER | DESCRIPTION |
|---|---|
ref
|
A reference to the column in the data source.
TYPE:
|
distribution
|
A dictionary with unique values as keys and tuples of minimum and maximum allowed shares as values.
TYPE:
|
default_bounds
|
A tuple specifying the minimum and maximum bounds for values not explicitly outlined in the target distribution dictionary.
TYPE:
|
name
|
An optional name for the constraint.
TYPE:
|
max_relative_violations
|
A tolerance threshold (0 to 1) for the proportion of elements in the data that can violate the bound constraints without triggering the constraint violation.
TYPE:
|
Source code in src/datajudge/constraints/uniques.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
NUniques
NUniques(ref: DataReference, *, ref2: DataReference | None = None, n_uniques: int | None = None, name: str | None = None, cache_size=None)
Bases: Constraint, ABC
Source code in src/datajudge/constraints/uniques.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
NUniquesEquality
NUniquesEquality(ref: DataReference, *, ref2: DataReference | None = None, n_uniques: int | None = None, name: str | None = None, cache_size=None)
Bases: NUniques
Source code in src/datajudge/constraints/uniques.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
NUniquesMaxGain
NUniquesMaxGain(ref: DataReference, ref2: DataReference, max_relative_gain_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: NUniques
Source code in src/datajudge/constraints/uniques.py
366 367 368 369 370 371 372 373 374 375 | |
max_relative_gain_getter
instance-attribute
max_relative_gain_getter = max_relative_gain_getter
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/uniques.py
394 395 396 | |
NUniquesMaxLoss
NUniquesMaxLoss(ref: DataReference, ref2: DataReference, max_relative_loss_getter: _ToleranceGetter, name: str | None = None, cache_size=None)
Bases: NUniques
Source code in src/datajudge/constraints/uniques.py
333 334 335 336 337 338 339 340 341 342 | |
max_relative_loss_getter
instance-attribute
max_relative_loss_getter = max_relative_loss_getter
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/uniques.py
360 361 362 | |
Uniques
Uniques(ref: DataReference, name: str | None = None, cache_size=None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, *, ref2: DataReference | None = None, uniques: Collection | None = None, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, max_relative_violations=0, compare_distinct=False)
Bases: Constraint, ABC
Uniques is an abstract class for comparisons between unique values of a column and a reference.
The Uniques constraint asserts if the values contained in a column of a DataSource
are part of a reference set of expected values - either externally supplied
through parameter uniques or obtained from another DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
There are two ways to do some post processing of the data obtained from the database by providing a function to be executed. In general, no postprocessing is needed, but there are some cases where it's the only thing to do. For example, with text values that have some structure.
One is map_func, it'll be executed over each obtained 'unique' value. This is a very
local operation.
If map_func is provided, it'll be executed over each obtained 'unique'
value.
The second one is reduce_func which will take the whole data retrieved and
can perform global processing. If it is provided, it gets applied after the function
given in map_func is finished. The output of this function has to be an iterable
(eager or lazy) of the same type as the type of the values of the column (in their
Python equivalent).
Furthermore, the max_relative_violations parameter can be used to set a tolerance
threshold for the proportion of elements in the data that can violate the constraint
(default: 0).
Setting this argument is currently not supported for UniquesEquality.
For UniquesSubset, by default,
the number of occurrences affects the computed fraction of violations.
To disable this weighting, set compare_distinct=True.
This argument does not have an effect on the test results for other Uniques constraints,
or if max_relative_violations is 0.
By default, the assertion messages make use of sets,
thus, they may differ from run to run despite the exact same situation being present,
and can have an arbitrary length.
To enforce a reproducible, limited output via (e.g.) sorting and slicing,
set output_processors to a callable or a list of callables. By default, only the first 100 elements are displayed (output_processor_limit).
Each callable takes in two collections, and returns modified (e.g. sorted) versions of them.
In most cases, the second argument is simply None,
but for UniquesSubset it is the counts of each of the elements.
The suggested functions are output_processor_sort and output_processor_limit
- see their respective docstrings for details.
One use is of this constraint is to test for consistency in columns with expected categorical values.
Source code in src/datajudge/constraints/uniques.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
UniquesEquality
UniquesEquality(args, name: str | None = None, cache_size=None, **kwargs)
Bases: Uniques
Source code in src/datajudge/constraints/uniques.py
169 170 171 172 173 174 175 176 | |
UniquesSubset
UniquesSubset(ref: DataReference, name: str | None = None, cache_size=None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, *, ref2: DataReference | None = None, uniques: Collection | None = None, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, max_relative_violations=0, compare_distinct=False)
Bases: Uniques
Source code in src/datajudge/constraints/uniques.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
UniquesSuperset
UniquesSuperset(args, name: str | None = None, cache_size=None, **kwargs)
Bases: Uniques
Source code in src/datajudge/constraints/uniques.py
261 262 263 264 | |
varchar
VarCharMaxLength
VarCharMaxLength(ref: DataReference, *, ref2: DataReference | None = None, max_length: int | None = None, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/varchar.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
VarCharMinLength
VarCharMinLength(ref, *, ref2: DataReference | None = None, min_length: int | None = None, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/varchar.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
VarCharRegex
VarCharRegex(ref: DataReference, regex: str, allow_none: bool = False, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/varchar.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
test
test(engine: Engine) -> TestResult
Source code in src/datajudge/constraints/varchar.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
VarCharRegexDb
VarCharRegexDb(ref: DataReference, regex: str, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, name: str | None = None, cache_size=None)
Bases: Constraint
Source code in src/datajudge/constraints/varchar.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
data_source
DataSource
Bases: ABC
ExpressionDataSource
ExpressionDataSource(expression: FromClause | Select, name: str)
Bases: DataSource
A DataSource based on a sqlalchemy expression.
Source code in src/datajudge/data_source.py
59 60 61 62 63 64 65 | |
name
instance-attribute
name = name
RawQueryDataSource
RawQueryDataSource(query_string: str, name: str, columns: list[str] | None = None)
Bases: DataSource
A DataSource based on a SQL query as a string.
Source code in src/datajudge/data_source.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
clause
instance-attribute
clause = subquery
name
instance-attribute
name = name
TableDataSource
TableDataSource(db_name: str, table_name: str, schema_name: str | None = None)
Bases: DataSource
A DataSource based on a table.
Source code in src/datajudge/data_source.py
27 28 29 30 31 32 33 34 35 | |
formatter
AnsiColorFormatter
AnsiColorFormatter()
Bases: Formatter
Source code in src/datajudge/formatter.py
28 29 30 | |
Formatter
Formatter()
Bases: ABC
Source code in src/datajudge/formatter.py
11 12 | |
fmt_str
fmt_str(string: str) -> str
Source code in src/datajudge/formatter.py
18 19 20 21 22 23 24 | |
pytest_integration
collect_data_tests
collect_data_tests(requirements: Iterable[Requirement])
Make a Pytest test case that checks all requirements.
Returns a function named test_constraint that is parametrized over all
constraints in requirements. The function requires a datajudge_engine
fixture that is a SQLAlchemy engine to be available.
Source code in src/datajudge/pytest_integration.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_formatter
get_formatter(pytestconfig)
Source code in src/datajudge/pytest_integration.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
requirements
BetweenRequirement
BetweenRequirement(data_source: DataSource, data_source2: DataSource, date_column: str | None = None, date_column2: str | None = None)
Bases: Requirement
Source code in src/datajudge/requirements.py
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 | |
add_column_subset_constraint
add_column_subset_constraint(name: str | None = None, cache_size=None) -> None
Columns of first table are subset of second table.
Source code in src/datajudge/requirements.py
2008 2009 2010 2011 2012 2013 2014 2015 2016 | |
add_column_superset_constraint
add_column_superset_constraint(name: str | None = None, cache_size=None) -> None
Columns of first table are superset of columns of second table.
Source code in src/datajudge/requirements.py
2018 2019 2020 2021 2022 2023 2024 2025 2026 | |
add_column_type_constraint
add_column_type_constraint(column1: str, column2: str, name: str | None = None, cache_size=None) -> None
Check that the columns have the same type.
Source code in src/datajudge/requirements.py
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 | |
add_date_max_constraint
add_date_max_constraint(column1: str, column2: str, use_upper_bound_reference: bool = True, column_type: str = 'date', condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Compare date max of first table to date max of second table.
The used columns of both tables need to be of the same type.
For more information on column_type values, see add_column_type_constraint.
If use_upper_bound_reference, the max of the first table has to be
smaller or equal to the max of the second table.
If not use_upper_bound_reference, the max of the first table has to
be greater or equal to the max of the second table.
Source code in src/datajudge/requirements.py
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 | |
add_date_min_constraint
add_date_min_constraint(column1: str, column2: str, use_lower_bound_reference: bool = True, column_type: str = 'date', condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure date min of first table is greater or equal date min of second table.
The used columns of both tables need to be of the same type.
For more information on column_type values, see add_column_type_constraint.
If use_lower_bound_reference, the min of the first table has to be
greater or equal to the min of the second table.
If not use_upper_bound_reference, the min of the first table has to
be smaller or equal to the min of the second table.
Source code in src/datajudge/requirements.py
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 | |
add_ks_2sample_constraint
add_ks_2sample_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, significance_level: float = 0.05, cache_size=None) -> None
Apply the so-called two-sample Kolmogorov-Smirnov test to the distributions of the two given columns.
The constraint is fulfilled, when the resulting p-value of the test is higher than the significance level (default is 0.05, i.e., 5%). The significance_level must be a value between 0.0 and 1.0.
Source code in src/datajudge/requirements.py
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 | |
add_max_null_fraction_constraint
add_max_null_fraction_constraint(column1: str, column2: str, max_relative_deviation: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the fraction of NULL values of one is at most that of the other.
Given that column2's underlying data has a fraction q of NULL values, the
max_relative_deviation parameter allows column1's underlying data to have a
fraction (1 + max_relative_deviation) * q of NULL values.
Source code in src/datajudge/requirements.py
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
add_n_rows_equality_constraint
add_n_rows_equality_constraint(condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 | |
add_n_rows_max_gain_constraint
add_n_rows_max_gain_constraint(constant_max_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't grown by more than expected.
In particular, assert that
See readme for more information on constant_max_relative_gain.
Source code in src/datajudge/requirements.py
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | |
add_n_rows_max_loss_constraint
add_n_rows_max_loss_constraint(constant_max_relative_loss: float | None = None, date_range_loss_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't decreased too much.
In particular, assert that
See readme for more information on constant_max_relative_loss.
Source code in src/datajudge/requirements.py
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 | |
add_n_rows_min_gain_constraint
add_n_rows_min_gain_constraint(constant_min_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of rows hasn't grown less than expected.
In particular, assert that
See readme for more information on constant_min_relative_gain.
Source code in src/datajudge/requirements.py
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 | |
add_n_uniques_equality_constraint
add_n_uniques_equality_constraint(columns1: list[str] | None, columns2: list[str] | None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | |
add_n_uniques_max_gain_constraint
add_n_uniques_max_gain_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_relative_gain: float | None = None, date_range_gain_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of uniques hasn't grown by too much.
In particular, assert that
The number of uniques in first table are defined based on columns1, the
number of uniques in second table are defined based on columns2.
See readme for more information on constant_max_relative_gain.
Source code in src/datajudge/requirements.py
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | |
add_n_uniques_max_loss_constraint
add_n_uniques_max_loss_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_relative_loss: float | None = None, date_range_loss_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the number of uniques hasn't decreased too much.
In particular, assert that
The number of uniques in first table are defined based on columns1, the
number of uniques in second table are defined based on columns2.
See readme for more information on constant_max_relative_loss.
Source code in src/datajudge/requirements.py
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
add_numeric_max_constraint
add_numeric_max_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 | |
add_numeric_mean_constraint
add_numeric_mean_constraint(column1: str, column2: str, max_absolute_deviation: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 | |
add_numeric_min_constraint
add_numeric_min_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 | |
add_numeric_percentile_constraint
add_numeric_percentile_constraint(column1: str, column2: str, percentage: float, max_absolute_deviation: float | None = None, max_relative_deviation: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the percentage-th percentile is approximately equal.
The percentile is defined as the smallest value present in column1 / column2
for which percentage % of the values in column1 / column2 are
less or equal. NULL values are ignored.
Hence, if percentage is less than the inverse of the number of non-NULL
rows, None is received as the percentage-th percentile.
percentage is expected to be provided in percent. The median, for example,
would correspond to percentage=50.
At least one of max_absolute_deviation and max_relative_deviation must
be provided.
Source code in src/datajudge/requirements.py
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 | |
add_row_equality_constraint
add_row_equality_constraint(columns1: list[str] | None, columns2: list[str] | None, max_missing_fraction: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T1 and T2 are absent in either.
In other words
Rows from T1 are indexed in columns1, rows from T2 are indexed in columns2.
Source code in src/datajudge/requirements.py
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 | |
add_row_matching_equality_constraint
add_row_matching_equality_constraint(matching_columns1: list[str], matching_columns2: list[str], comparison_columns1: list[str], comparison_columns2: list[str], max_missing_fraction: float, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Match tables in matching_columns, compare for equality in comparison_columns.
This constraint is similar to the nature of the RowEquality
constraint. Just as the latter, this constraint divides the
cardinality of an intersection by the cardinality of a union.
The difference lies in how the set are created. While RowEquality
considers all rows of both tables, indexed in columns,
RowMatchingEquality considers only rows in both tables having values
in matching_columns present in both tables. At most max_missing_fraction
of such rows can be missing in the intersection.
Alternatively, this can be thought of as counting mismatches in
comparison_columns after performing an inner join on matching_columns.
Source code in src/datajudge/requirements.py
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 | |
add_row_subset_constraint
add_row_subset_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_missing_fraction: float | None, date_range_loss_fraction: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T1 are not in T2.
In other words,
:math:\frac{|T1-T2|}{|T1|} \leq max_missing_fraction.
Rows from T1 are indexed in columns1, rows from T2 are indexed in columns2.
In particular, the operation |T1-T2| relies on a sql EXCEPT statement. In
contrast to EXCEPT ALL, this should lead to a set subtraction instead of
a multiset subtraction. In other words, duplicates in T1 are treated as
single occurrences.
Source code in src/datajudge/requirements.py
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 | |
add_row_superset_constraint
add_row_superset_constraint(columns1: list[str] | None, columns2: list[str] | None, constant_max_missing_fraction: float, date_range_loss_fraction: float | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
At most max_missing_fraction of rows in T2 are not in T1.
In other words, \(\frac{|T2-T1|}{|T2|} \leq\) max_missing_fraction.
Rows from T1 are indexed in columns1, rows from T2 are indexed in
columns2.
Source code in src/datajudge/requirements.py
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 | |
add_uniques_equality_constraint
add_uniques_equality_constraint(columns1: list[str], columns2: list[str], filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Check if the data's unique values in given columns are equal.
The UniquesEquality constraint asserts if the values contained in a column
of a DataSource's columns, are strictly the ones of another DataSource's
columns.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly..
See Uniques for further parameter details on map_func,
reduce_func, and output_processors.
Source code in src/datajudge/requirements.py
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 | |
add_uniques_subset_constraint
add_uniques_subset_constraint(columns1: list[str], columns2: list[str], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, compare_distinct: bool = False, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None) -> None
Check if the given columns's unique values in are contained in reference data.
The UniquesSubset constraint asserts if the values contained in given column of
a DataSource are part of the unique values of given columns of another
DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of rows of the given table
may have values not included in the reference set of unique values. Please note
that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
By default, the number of occurrences affects the computed fraction of violations.
To disable this weighting, set compare_distinct=True.
This argument does not have an effect on the test results for other Uniques constraints,
or if max_relative_violations is 0.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 | |
add_uniques_superset_constraint
add_uniques_superset_constraint(columns1: list[str], columns2: list[str], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None) -> None
Check if unique values of columns are contained in the reference data.
The UniquesSuperset constraint asserts that reference set of expected values,
derived from the unique values in given columns of the reference DataSource,
is contained in given columns of a DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly..
max_relative_violations indicates what fraction of unique values of the given
DataSource are not represented in the reference set of unique values. Please
note that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
One use of this constraint is to test for consistency in columns with expected categorical values.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 | |
add_varchar_max_length_constraint
add_varchar_max_length_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 | |
add_varchar_min_length_constraint
add_varchar_min_length_constraint(column1: str, column2: str, condition1: Condition | None = None, condition2: Condition | None = None, name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 | |
from_expressions
classmethod
from_expressions(expression1, expression2, name1: str, name2: str, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenTableRequirement based on sqlalchemy expressions.
Any sqlalchemy object implementing the alias method can be passed as an
argument for the expression1 and expression2 parameters. This could,
e.g. be a sqlalchemy.Table object or the result of a sqlalchemy.select
invocation.
name1 and name2 will be used to represent the expressions in error messages,
respectively.
Source code in src/datajudge/requirements.py
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | |
from_raw_queries
classmethod
from_raw_queries(query1: str, query2: str, name1: str, name2: str, columns1: list[str] | None = None, columns2: list[str] | None = None, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenRequirement based on raw query strings.
The query1 and query2 parameters can be passed any query string returning
rows, e.g. "SELECT * FROM myschema.mytable LIMIT 1337" or
"SELECT id, name FROM table1 UNION SELECT id, name FROM table2".
name1 and name2 will be used to represent the queries in error messages,
respectively.
If constraints rely on specific columns, these should be provided here via
columns1 and columns2 respectively.
Source code in src/datajudge/requirements.py
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 | |
from_tables
classmethod
from_tables(db_name1: str, schema_name1: str, table_name1: str, db_name2: str, schema_name2: str, table_name2: str, date_column: str | None = None, date_column2: str | None = None)
Create a BetweenRequirement based on a table.
Source code in src/datajudge/requirements.py
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
Requirement
Requirement()
Bases: ABC, MutableSequence
Source code in src/datajudge/requirements.py
63 64 65 | |
insert
insert(index: int, value: Constraint) -> None
Source code in src/datajudge/requirements.py
67 68 | |
test
test(engine) -> list[TestResult]
Source code in src/datajudge/requirements.py
82 83 | |
TableQualifier
TableQualifier(db_name: str, schema_name: str, table_name: str)
Source code in src/datajudge/requirements.py
39 40 41 42 | |
get_between_requirement
get_between_requirement(table_qualifier)
Source code in src/datajudge/requirements.py
51 52 53 54 55 56 57 58 59 | |
get_within_requirement
get_within_requirement()
Source code in src/datajudge/requirements.py
44 45 46 47 48 49 | |
WithinRequirement
WithinRequirement(data_source: DataSource)
Bases: Requirement
Source code in src/datajudge/requirements.py
87 88 89 | |
add_categorical_bound_constraint
add_categorical_bound_constraint(columns: list[str], distribution: dict[_T, tuple[float, float]], default_bounds: tuple[float, float] = (0, 0), max_relative_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Check if the distribution of unique values in columns falls within the specified minimum and maximum bounds.
The CategoricalBoundConstraint is added to ensure the distribution of unique values
in the specified columns of a DataSource falls within the given minimum and maximum
bounds defined in the distribution parameter.
| PARAMETER | DESCRIPTION |
|---|---|
columns
|
A list of column names from the
TYPE:
|
distribution
|
A dictionary where keys represent unique values and the corresponding tuple values represent the minimum and maximum allowed proportions of the respective unique value in the columns.
TYPE:
|
default_bounds
|
A tuple specifying the minimum and maximum allowed proportions for all
elements not mentioned in the distribution. By default, it's set to (0, 0), which means
all elements not present in
TYPE:
|
max_relative_violations
|
A tolerance threshold (0 to 1) for the proportion of elements in the data that can violate the bound constraints without triggering the constraint violation.
TYPE:
|
condition
|
An optional parameter to specify a
TYPE:
|
name
|
An optional parameter to provide a custom name for the constraint.
TYPE:
|
cache_size
|
TODO
DEFAULT:
|
Example:
This method can be used to test for consistency in columns with expected categorical values or ensure that the distribution of values in a column adheres to a certain criterion.
Usage:
requirement = WithinRequirement(data_source)
requirement.add_categorical_bound_constraint(
columns=['column_name'],
distribution={'A': (0.2, 0.3), 'B': (0.4, 0.6), 'C': (0.1, 0.2)},
max_relative_violations=0.05,
name='custom_name'
)
Source code in src/datajudge/requirements.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
add_column_existence_constraint
add_column_existence_constraint(columns: list[str], name: str | None = None, cache_size=None) -> None
Source code in src/datajudge/requirements.py
127 128 129 130 131 132 133 134 | |
add_column_type_constraint
add_column_type_constraint(column: str, column_type: str | TypeEngine, name: str | None = None, cache_size=None) -> None
Check if a column type matches the expected column_type.
The column_type can be provided as a string (backend-specific type name), a backend-specific SQLAlchemy type, or a SQLAlchemy's generic type.
If SQLAlchemy's generic types are used, the check is performed using isinstance, which means that the actual type can also be a subclass of the target type.
For more information on SQLAlchemy's generic types, see https://docs.sqlalchemy.org/en/20/core/type_basics.html
| PARAMETER | DESCRIPTION |
|---|---|
column
|
The name of the column to which the constraint will be applied.
TYPE:
|
column_type
|
The expected type of the column. This can be a string, a backend-specific SQLAlchemy type, or a generic SQLAlchemy type.
TYPE:
|
name
|
An optional name for the constraint. If not provided, a name will be generated automatically.
TYPE:
|
Source code in src/datajudge/requirements.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
add_date_between_constraint
add_date_between_constraint(column: str, lower_bound: str, upper_bound: str, min_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Use string format: lower_bound="'20121230'".
Source code in src/datajudge/requirements.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
add_date_max_constraint
add_date_max_constraint(column: str, max_value: str, use_upper_bound_reference: bool = True, column_type: str = 'date', condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure all dates to be superior than max_value.
Use string format: max_value="'20121230'"
For more information on column_type values, see add_column_type_constraint.
If use_upper_bound_reference is True, the maximum date in column has to be smaller or
equal to max_value. Otherwise the maximum date in column has to be greater or equal
to max_value.
Source code in src/datajudge/requirements.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
add_date_min_constraint
add_date_min_constraint(column: str, min_value: str, use_lower_bound_reference: bool = True, column_type: str = 'date', condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Ensure all dates to be superior than min_value.
Use string format: min_value="'20121230'".
For more information on column_type values, see add_column_type_constraint.
If use_lower_bound_reference, the min of the first table has to be
greater or equal to min_value.
If not use_upper_bound_reference, the min of the first table has to
be smaller or equal to min_value.
Source code in src/datajudge/requirements.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
add_date_no_gap_constraint
add_date_no_gap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Express that date range rows have no gap in-between them.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Additionally, a start_column and an end_column,
indicating start and end dates, should be provided.
Neither of those columns should contain NULL values. Also, it should hold that
for a given row, the value of end_column is strictly greater than the value of
start_column.
Note that the value of start_column is expected to be included in each date range.
By default, the value of end_column is expected to be included as well - this can
however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often has
several rows. Thereby, a key will often come with several date ranges.
If key_columns is None or [], all columns of the table will be
considered as composing the key.
In order to express a tolerance for some violations of this gap property, use the
max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one gap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
add_date_no_overlap_2d_constraint
add_date_no_overlap_2d_constraint(start_column1: str, end_column1: str, start_column2: str, end_column2: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Express that several date range rows do not overlap in two date dimensions.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Per date dimension, a start column (start_column1, start_column2)
and end (end_column1, end_column2) column should be provided in order to define
date ranges.
Date ranges in different date dimensions are expected to represent different kinds
of dates. For example, let's say that a row in a table indicates an averag temperature
forecast. start_column1 and end_column1 could the date span that was forecasted,
e.g. the weather from next Saturday to next Sunday. end_column1 and end_column2
might indicate the timespan when this forceast was used, e.g. from the
previous Monday to Wednesday.
Neither of those columns should contain NULL values. Also, the value of end_column_k
should be strictly greater than the value of start_column_k.
Note that the values of start_column1 and start_column2 are expected to be
included in each date range. By default, the values of end_column1 and
end_column2 are expected to be included as well - this can however be changed
by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of interest. A priori, a key is not a primary key, i.e., a key can have and often has several rows. Thereby, a key will often come with several date ranges.
Often, you might want the date ranges for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered as
composing the key.
In order to express a tolerance for some violations of this non-overlapping property,
use the max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
add_date_no_overlap_constraint
add_date_no_overlap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Constraint expressing that several date range rows may not overlap.
The DataSource under inspection must consist of at least one but up
to many key_columns, identifying an entity, a start_column and an
end_column.
For a given row in this DataSource, start_column and end_column indicate a
date range. Neither of those columns should contain NULL values. Also, it
should hold that for a given row, the value of end_column is strictly greater
than the value of start_column.
Note that the value of start_column is expected to be included in each date
range. By default, the value of end_column is expected to be included as well -
this can however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often
has several rows. Thereby, a key will often come with several date ranges.
Often, you might want the date ranges for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered
as composing the key.
In order to express a tolerance for some violations of this non-overlapping
property, use the max_relative_n_violations parameter. The latter expresses for
what fraction of all key values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
add_functional_dependency_constraint
add_functional_dependency_constraint(key_columns: list[str], value_columns: list[str], condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Expresses a functional dependency, a constraint where the value_columns are uniquely determined by the key_columns.
This means that for each unique combination of values in the key_columns, there is exactly one corresponding combination of values in the value_columns.
The add_unique_constraint constraint is a special case of this constraint, where the key_columns are a primary key,
and all other columns are included value_columns.
This constraint allows for a more general definition of functional dependencies, where the key_columns are not necessarily a primary key.
An additional configuration option (for details see the analogous parameter in for Uniques-constraints)
on how the output is sorted and how many counterexamples are shown is available as output_processors.
An additional configuration option (for details see the analogous parameter in for Uniques-constraints)
on how the output is sorted and how many counterexamples are shown is available as output_processors.
For more information on functional dependencies, see https://en.wikipedia.org/wiki/Functional_dependency.
Source code in src/datajudge/requirements.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
add_groupby_aggregation_constraint
add_groupby_aggregation_constraint(columns: Sequence[str], aggregation_column: str, start_value: int, tolerance: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Check whether array aggregate corresponds to an integer range.
The DataSource is grouped by columns. Sql's array_agg function is then
applied to the aggregate_column.
Since we expect aggregate_column to be a numeric column, this leads to
a multiset of aggregated values. These values should correspond to the integers
ranging from start_value to the cardinality of the multiset.
In order to allow for slight deviations from this pattern, tolerance expresses
the fraction of all grouped-by rows, which may be incomplete ranges.
Source code in src/datajudge/requirements.py
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 | |
add_max_null_fraction_constraint
add_max_null_fraction_constraint(column: str, max_null_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None)
Assert that column has less than a certain fraction of NULL values.
max_null_fraction is expected to lie within [0, 1].
Source code in src/datajudge/requirements.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
add_n_rows_equality_constraint
add_n_rows_equality_constraint(n_rows: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
259 260 261 262 263 264 265 266 267 268 269 270 271 | |
add_n_rows_max_constraint
add_n_rows_max_constraint(n_rows_max: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
287 288 289 290 291 292 293 294 295 296 297 298 299 | |
add_n_rows_min_constraint
add_n_rows_min_constraint(n_rows_min: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
273 274 275 276 277 278 279 280 281 282 283 284 285 | |
add_n_uniques_equality_constraint
add_n_uniques_equality_constraint(columns: list[str] | None, n_uniques: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
add_null_absence_constraint
add_null_absence_constraint(column: str, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
223 224 225 226 227 228 229 230 231 232 233 234 235 | |
add_numeric_between_constraint
add_numeric_between_constraint(column: str, lower_bound: float, upper_bound: float, min_fraction: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the column's values lie between lower_bound and upper_bound.
Note that both bounds are inclusive.
Unless specified otherwise via the usage of a condition, NULL values will
be considered in the denominator of min_fraction. NULL values will never be
considered to lie in the interval [lower_bound, upper_bound].
Source code in src/datajudge/requirements.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
add_numeric_max_constraint
add_numeric_max_constraint(column: str, max_value: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
All values in column are less or equal max_value.
Source code in src/datajudge/requirements.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
add_numeric_mean_constraint
add_numeric_mean_constraint(column: str, mean_value: float, max_absolute_deviation: float, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert the mean of the column column deviates at most max_deviation from mean_value.
Source code in src/datajudge/requirements.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
add_numeric_min_constraint
add_numeric_min_constraint(column: str, min_value: float, condition: Condition | None = None, cache_size=None) -> None
All values in column are greater or equal min_value.
Source code in src/datajudge/requirements.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
add_numeric_no_gap_constraint
add_numeric_no_gap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, legitimate_gap_size: float = 0, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Express that numeric interval rows have no gaps larger than some max value in-between them.
The table under inspection must consist of at least one but up to many key columns,
identifying an entity. Additionally, a start_column and an end_column,
indicating interval start and end values, should be provided.
Neither of those columns should contain NULL values. Also, it should hold that
for a given row, the value of end_column is strictly greater than the value of
start_column.
legitimate_gap_size is the maximum tollerated gap size between two intervals.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often has
several rows. Thereby, a key will often come with several intervals.
If key_columns is None or [], all columns of the table will be
considered as composing the key.
In order to express a tolerance for some violations of this gap property, use the
max_relative_n_violations parameter. The latter expresses for what fraction
of all key_values, at least one gap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | |
add_numeric_no_overlap_constraint
add_numeric_no_overlap_constraint(start_column: str, end_column: str, key_columns: list[str] | None = None, end_included: bool = True, max_relative_n_violations: float = 0, condition: Condition | None = None, name: str | None = None, cache_size=None)
Constraint expressing that several numeric interval rows may not overlap.
The DataSource under inspection must consist of at least one but up
to many key_columns, identifying an entity, a start_column and an
end_column.
For a given row in this DataSource, start_column and end_column indicate a
numeric interval. Neither of those columns should contain NULL values. Also, it
should hold that for a given row, the value of end_column is strictly greater
than the value of start_column.
Note that the value of start_column is expected to be included in each interval.
By default, the value of end_column is expected to be included as well -
this can however be changed by setting end_included to False.
A 'key' is a fixed set of values in key_columns and represents an entity of
interest. A priori, a key is not a primary key, i.e., a key can have and often
has several rows. Thereby, a key will often come with several intervals.
Often, you might want the intervals for a given key not to overlap.
If key_columns is None or [], all columns of the table will be considered
as composing the key.
In order to express a tolerance for some violations of this non-overlapping
property, use the max_relative_n_violations parameter. The latter expresses for
what fraction of all key values, at least one overlap may exist.
For illustrative examples of this constraint, please refer to its test cases.
Source code in src/datajudge/requirements.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 | |
add_numeric_percentile_constraint
add_numeric_percentile_constraint(column: str, percentage: float, expected_percentile: float, max_absolute_deviation: float | None = None, max_relative_deviation: float | None = None, condition: Condition | None = None, name: str | None = None, cache_size=None) -> None
Assert that the percentage-th percentile is approximately expected_percentile.
The percentile is defined as the smallest value present in column for which
percentage % of the values in column are less or equal. NULL values
are ignored.
Hence, if percentage is less than the inverse of the number of non-NULL rows,
None is received as the percentage -th percentile.
percentage is expected to be provided in percent. The median, for example, would
correspond to percentage=50.
At least one of max_absolute_deviation and max_relative_deviation must
be provided.
Source code in src/datajudge/requirements.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
add_primary_key_definition_constraint
add_primary_key_definition_constraint(primary_keys: list[str], name: str | None = None, cache_size=None) -> None
Check that the primary key constraints in the database are exactly equal to the given column names.
Note that this doesn't actually check that the primary key values are unique across the table.
Source code in src/datajudge/requirements.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
add_uniqueness_constraint
add_uniqueness_constraint(columns: list[str] | None = None, max_duplicate_fraction: float = 0, condition: Condition | None = None, max_absolute_n_duplicates: int = 0, infer_pk_columns: bool = False, name: str | None = None, cache_size=None) -> None
Columns should uniquely identify row.
Given a list of columns columns, validate the condition of a primary key, i.e.
uniqueness of tuples in said columns. This constraint has a tolerance
for inconsistencies, expressed via max_duplicate_fraction. The latter
suggests that the number of uniques from said columns is larger or equal
to 1 - max_duplicate_fraction times the number of rows.
If infer_pk_columns is True, columns will be retrieved from the primary keys.
If columns is None and infer_pk_column is False, the fallback is
validating that all rows in a table are unique.
Source code in src/datajudge/requirements.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
add_uniques_equality_constraint
add_uniques_equality_constraint(columns: list[str], uniques: Collection[_T], filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, condition: Condition | None = None, name: str | None = None, cache_size=None)
Check if the data's unique values are equal to a given set of values.
The UniquesEquality constraint asserts if the values contained in a column
of a DataSource are strictly the ones of a reference set of expected values,
specified via the uniques parameter.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
See the Uniques class for further parameter details on map_func and
reduce_func, and output_processors.
Source code in src/datajudge/requirements.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
add_uniques_subset_constraint
add_uniques_subset_constraint(columns: list[str], uniques: Collection[_T], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, compare_distinct: bool = False, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Check if the data's unique values are contained in a given set of values.
The UniquesSubset constraint asserts if the values contained in a column of
a DataSource are part of a reference set of expected values, specified via
uniques.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
Cause (possibly often unintended) changes in behavior when the users adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of rows of the given table
may have values not included in the reference set of unique values. Please note
that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
By default, the number of occurrences affects the computed fraction of violations.
To disable this weighting, set compare_distinct=True.
This argument does not have an effect on the test results for other Uniques constraints,
or if max_relative_violations is 0.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
add_uniques_superset_constraint
add_uniques_superset_constraint(columns: list[str], uniques: Collection[_T], max_relative_violations: float = 0, filter_func: Callable[[list[_T]], list[_T]] | None = None, map_func: Callable[[_T], _T] | None = None, reduce_func: Callable[[Collection], Collection] | None = None, condition: Condition | None = None, name: str | None = None, output_processors: OutputProcessor | list[OutputProcessor] | None = output_processor_limit, cache_size=None)
Check if unique values of columns are contained in the reference data.
The UniquesSuperset constraint asserts that reference set of expected values,
specified via uniques, is contained in given columns of a DataSource.
Null values in the columns columns are ignored. To assert the non-existence of them use
the add_null_absence_constraint helper method
for WithinRequirement.
By default, the null filtering does not trigger if multiple columns are fetched at once.
It can be configured in more detail by supplying a custom filter_func function.
Some exemplary implementations are available as filternull_element,
filternull_never, filternull_element_or_tuple_all,
filternull_element_or_tuple_any.
Passing None as the argument is equivalent to filternull_element but triggers a warning.
The current default of filternull_element
will cause (possibly often unintended) changes in behavior when the user adds a second column
(filtering no longer can trigger at all).
The default will be changed to filternull_element_or_tuple_all in future versions.
To silence the warning, set filter_func explicitly.
max_relative_violations indicates what fraction of unique values of the given
DataSource are not represented in the reference set of unique values. Please
note that UniquesSubset and UniquesSuperset are not symmetrical in this regard.
One use of this constraint is to test for consistency in columns with expected categorical values.
See Uniques for further details on map_func, reduce_func,
and output_processors.
Source code in src/datajudge/requirements.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
add_varchar_max_length_constraint
add_varchar_max_length_constraint(column: str, max_length: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
add_varchar_min_length_constraint
add_varchar_min_length_constraint(column: str, min_length: int, condition: Condition | None = None, name: str | None = None, cache_size=None)
Source code in src/datajudge/requirements.py
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
add_varchar_regex_constraint
add_varchar_regex_constraint(column: str, regex: str, condition: Condition | None = None, name: str | None = None, allow_none: bool = False, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, cache_size=None)
Assesses whether the values in a column match a given regular expression pattern.
The option allow_none can be used in cases where the column is defined as
nullable and contains null values.
How the tolerance factor is calculated can be controlled with the aggregated
flag. When True, the tolerance is calculated using unique values. If not, the
tolerance is calculated using all the instances of the data.
n_counterexamples defines how many counterexamples are displayed in an
assertion text. If all counterexamples are meant to be shown, provide -1 as
an argument.
When using this method, the regex matching will take place in memory. If instead,
you would like the matching to take place in database which is typically faster and
substantially more memory-saving, please consider using
add_varchar_regex_constraint_db.
Source code in src/datajudge/requirements.py
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
add_varchar_regex_constraint_db
add_varchar_regex_constraint_db(column: str, regex: str, condition: Condition | None = None, name: str | None = None, relative_tolerance: float = 0.0, aggregated: bool = True, n_counterexamples: int = 5, cache_size=None)
Assesses whether the values in a column match a given regular expression pattern.
How the tolerance factor is calculated can be controlled with the aggregated
flag. When True, the tolerance is calculated using unique values. If not, the
tolerance is calculated using all the instances of the data.
n_counterexamples defines how many counterexamples are displayed in an
assertion text. If all counterexamples are meant to be shown, provide -1 as
an argument.
When using this method, the regex matching will take place in database, which is
only supported for Postgres, Sqllite and Snowflake. Note that for this
feature is only for Snowflake when using sqlalchemy-snowflake >= 1.4.0. As an
alternative, add_varchar_regex_constraint performs the regex matching in memory.
This is typically slower and more expensive in terms of memory but available
on all supported database mamangement systems.
Source code in src/datajudge/requirements.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | |
from_expression
classmethod
from_expression(expression: FromClause, name: str)
Create a WithinRequirement based on a sqlalchemy expression.
Any sqlalchemy object implementing the alias method can be passed as an
argument for the expression parameter. This could, e.g. be an
sqlalchemy.Table object or the result of a sqlalchemy.select call.
The name will be used to represent this expression in error messages.
Source code in src/datajudge/requirements.py
115 116 117 118 119 120 121 122 123 124 125 | |
from_raw_query
classmethod
from_raw_query(query: str, name: str, columns: list[str] | None = None)
Create a WithinRequirement based on a raw query string.
The query parameter can be passed any query string returning rows, e.g.
"SELECT * FROM myschema.mytable LIMIT 1337" or
"SELECT id, name FROM table1 UNION SELECT id, name FROM table2".
The name will be used to represent this query in error messages.
If constraints rely on specific columns, these should be provided here via
columns, e.g. ["id", "name"].
Source code in src/datajudge/requirements.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
from_table
classmethod
from_table(db_name: str, schema_name: str, table_name: str)
Create a WithinRequirement based on a table.
Source code in src/datajudge/requirements.py
91 92 93 94 95 96 97 98 | |
utils
OutputProcessor
Bases: Protocol
filternull_element
filternull_element(values: list) -> list
Source code in src/datajudge/utils.py
125 126 | |
filternull_element_or_tuple_all
filternull_element_or_tuple_all(values: list) -> list
Source code in src/datajudge/utils.py
133 134 135 136 137 138 139 | |
filternull_element_or_tuple_any
filternull_element_or_tuple_any(values: list) -> list
Source code in src/datajudge/utils.py
142 143 144 145 146 147 148 | |
filternull_never
filternull_never(values: list) -> list
Source code in src/datajudge/utils.py
129 130 | |
format_difference
format_difference(n1: float | int, n2: float | int, decimal_separator: bool = True) -> tuple[str, str]
Format and highlight how two numbers differ.
Given two numbers, n1 and n2, return a tuple of two strings, each representing one of the input numbers with the differing part highlighted. Highlighting is done using BBCode-like tags, which are replaced by the formatter.
Examples:
123, 123.0
-> 123, 123[numDiff].0[/numDiff]
122593859432, 122593859432347
-> 122593859432, 122593859432[numDiff]347[/numDiff]
Args: - n1: The first number to compare. - n2: The second number to compare. - decimal_separator: Whether to separate the decimal part of the numbers with commas.
| RETURNS | DESCRIPTION |
|---|---|
- A tuple of two strings, each representing one of the input numbers with the differing part highlighted.
|
|
Source code in src/datajudge/utils.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
output_processor_limit
output_processor_limit(collection: Collection, counts: Collection | None = None, limit: int = 100) -> tuple[Collection, Collection | None]
Limits the collection to the first limit elements.
If the list was shortened, will add a limit+1-th string element,
informing the user of the truncation.
The default limit of 100 can be adjusted using functools.partial.
Source code in src/datajudge/utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
output_processor_sort
output_processor_sort(collection: Collection, counts: Collection | None = None) -> tuple[Collection, Collection | None]
Sorts a collection of tuple elements in descending order of their counts.
If ties exist, the ascending order of the elements themselves is used.
If the first element is not instanceof tuple, each element will be transparently packaged into a 1-tuple for processing; this process is not visible to the caller.
Handles None values as described in sort_tuple_none_aware.
Source code in src/datajudge/utils.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
sort_tuple_none_aware
sort_tuple_none_aware(collection: Collection[tuple], ascending=True) -> Collection[tuple]
Stable sort of a collection of tuples.
Each tuple in the collection must have the same length,
since they are treated as rows in a table,
with elem[0] being the first column,
elem[1] the second, etc. for each elem in collection.
For sorting, None is considered the same as the default value of the respective column's type.
ints and floats int() and float() yield 0 and 0.0 respectively; for strings, str() yields ''.
The constructor is determined by calling type on the first non-None element of the respective column.
Validates that all elements in collection are tuples and that all tuples have the same length.
Source code in src/datajudge/utils.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |