constraints#
Defines Constraint
types.
Constraints are necessary for most aggregations on tables using the
AddRowsWithID
ProtectedChange
.
Illustrated examples using constraints can be found in the Working with privacy IDs tutorial.
Functions#
- simplify_constraints(constraints)#
Remove redundant constraints from a list of constraints.
Given a list of the constraints on a table, produce a copy which simplifies it as much as possible by removing or combining constraints which provide overlapping information. The original list is not modified.
- Parameters:
constraints (List[tmlt.analytics.constraints._base.Constraint])
- Return type:
Classes#
A known, enforceable fact about a table. |
|
A constraint limiting the number of rows associated with each ID in a table. |
|
A constraint limiting the number of distinct groups per ID. |
|
A constraint limiting rows per unique (ID, grouping column) pair in a table. |
- class Constraint#
Bases:
abc.ABC
A known, enforceable fact about a table.
Constraints provide information about the contents of a table to help produce differentially-private results. For example, a constraint might say that each ID in a table corresponds to no more than two rows in that table (the
MaxRowsPerID
constraint). Constraints are applied via theQueryBuilder.enforce()
method.This class is a base class for all constraints, and cannot be used directly.
- class MaxRowsPerID#
Bases:
tmlt.analytics.constraints._base.Constraint
A constraint limiting the number of rows associated with each ID in a table.
This constraint limits how many times each distinct value may appear in the ID column of a table with the
AddRowsWithID
protected change. For example,MaxRowsPerID(5)
guarantees that each ID appears in at most five rows. It cannot be applied to tables with other protected changes.
- class MaxGroupsPerID#
Bases:
tmlt.analytics.constraints._base.Constraint
A constraint limiting the number of distinct groups per ID.
This constraint limits how many times a distinct value may appear in the grouping column for each distinct value in the table’s ID column. For example,
MaxGroupsPerID("grouping_column", 4)
guarantees that there are at most four distinct values ofgrouping_column
for each distinct value ofID_column
.
- class MaxRowsPerGroupPerID#
Bases:
tmlt.analytics.constraints._base.Constraint
A constraint limiting rows per unique (ID, grouping column) pair in a table.
For example,
MaxRowsPerGroupPerID("group_col", 5)
guarantees that each ID appears in at most five rows for each distinct value ingroup_col
.