Questions or feedback?

opendp.domains module#

The domains module provides functions for creating and using domains. For more context, see domains in the User Guide.

For convenience, all the functions of this module are also available from opendp.prelude. We suggest importing under the conventional name dp:

>>> import opendp.prelude as dp
opendp.domains.array_domain(element_domain, width)[source]#

Construct an instance of ArrayDomain. Can be used as an argument to a Polars series domain.

Parameters:
  • element_domain (Domain) – The domain of each element in the array.

  • width (int) – The width of the array.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.atom_domain(bounds=None, nan=None, T=None)[source]#

Construct an instance of AtomDomain.

The domain defaults to unbounded if bounds is None, If T is float, nan defaults to true.

atom_domain in Rust documentation.

Parameters:
  • bounds – Optional bounds of elements in the domain, if the data type is numeric.

  • nan – Whether the domain may contain NaN, if the data type is float.

  • T (Type Argument) – The type of the atom.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Example:

Return type:

AtomDomain

>>> dp.atom_domain(T=float, nan=False)
AtomDomain(T=f64)
opendp.domains.bitvector_domain(max_weight=None)[source]#

Construct an instance of BitVectorDomain.

Parameters:

max_weight – The maximum number of positive bits.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.categorical_domain(categories=None)[source]#

Construct an instance of CategoricalDomain. Can be used as an argument to a Polars series domain.

Parameters:

categories – Optional ordered set of valid string categories

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.datetime_domain(time_unit='us', time_zone=None)[source]#

Construct an instance of DatetimeDomain.

Documentation on valid time zones can be found in the Polars documentation.

datetime_domain in Rust documentation.

Parameters:
  • time_unit (str) – One of ns, us or ms, corresponding to nano-, micro-, and milliseconds

  • time_zone (str) – Optional time zone.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.domain_carrier_type(this)[source]#

Get the carrier type of a domain.

Parameters:

this (Domain) – The domain to retrieve the carrier type from.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

str

opendp.domains.domain_debug(this)[source]#

Debug a domain.

Parameters:

this (Domain) – The domain to debug (stringify).

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

str

opendp.domains.domain_type(this)[source]#

Get the type of a domain.

Parameters:

this (Domain) – The domain to retrieve the type from.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

str

opendp.domains.enum_domain(categories)[source]#

Construct an instance of EnumDomain. Can be used as an argument to a Polars series domain.

Parameters:

categories – Optional ordered set of string categories

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.lazyframe_domain(series_domains)[source]#

Construct an instance of LazyFrameDomain.

Parameters:

series_domains – Domain of each series in the lazyframe.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

LazyFrameDomain

opendp.domains.map_domain(key_domain, value_domain)[source]#

Construct an instance of MapDomain.

Parameters:
  • key_domain (Domain) – domain of keys in the hashmap

  • value_domain (Domain) – domain of values in the hashmap

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.member(this, val)[source]#

Check membership in a domain.

Parameters:
  • this (Domain) – The domain to check membership in.

  • val – A potential element of the domain.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

bool

opendp.domains.option_domain(element_domain, D=None)[source]#

Construct an instance of OptionDomain.

option_domain in Rust documentation.

Parameters:
Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

OptionDomain

opendp.domains.series_domain(name, element_domain)[source]#

Construct an instance of SeriesDomain.

series_domain in Rust documentation.

Parameters:
  • name (str) – The name of the series.

  • element_domain (Domain) – The domain of elements in the series.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

SeriesDomain

opendp.domains.user_domain(identifier, member, descriptor=None)[source]#

Construct a new UserDomain. Any two instances of an UserDomain are equal if their string descriptors are equal. Contains a function used to check if any value is a member of the domain.

Required features: honest-but-curious

Why honest-but-curious?:

The identifier must uniquely identify this domain. If the identifier is not uniquely identifying, then two different domains with the same identifier will chain, which can violate transformation stability.

In addition, the member function must:

  1. be a pure function

  2. be sound (only return true if its input is a member of the domain).

Parameters:
  • identifier (str) – A string description of the data domain.

  • member – A function used to test if a value is a member of the data domain.

  • descriptor – Additional constraints on the domain.

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.vector_domain(atom_domain, size=None)[source]#

Construct an instance of VectorDomain.

Parameters:
  • atom_domain (Domain) – The inner domain.

  • size

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

VectorDomain

opendp.domains.wild_expr_domain(columns, margin=None)[source]#

Construct a WildExprDomain.

Required features: contrib

Parameters:
  • columns – descriptors for each column in the data

  • margin – descriptors for grouped data

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

Domain

opendp.domains.with_margin(frame_domain, margin)[source]#
Parameters:
  • frame_domain (Domain) –

  • margin

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

Return type:

LazyFrameDomain