Symbolic Constraints
Website: https://abogical.github.io/symconstraints/
Validate and impute your dataset with mathematical expressions.
Symbolic Constraints, or symconstraints for short, allows you to express your dataset rules
using mathematical equations and expressions. It makes use of the powerful SymPy Computer Algebra System to analyze
mathematical expressions and infer all possible validation and imputation methods to your datasets.
Installation
Symbolic constraints can be installed via pip:
pip install symconstraints
Features
🪄 Automatic inference
symconstraints uses SymPy to rearrange your formulas and find new ways to validate and impute your data.
Example
Given the constraints $a < 3b$ and $c > b^2 + 1$:
>>> from symconstraints import Constraints, symbols
>>> a, b, c = symbols('a b c')
>>> constraints = Constraints([a < 3*b, c > b**2 + 1])
>>> for validation in constraints.validations
... print(validation)
Validation: (b, a) => [a < 3*b] inferred by (a < 3*b)
Validation: (b, c) => [c > b**2 + 1] inferred by (c > b**2 + 1)
Validation: (a, c) => [a/3 < sqrt(c - 1)] inferred by (c > b**2 + 1, a < 3*b)
It automatically infers that $\frac{a}{3} < \sqrt{c-1}$.
🧩 Integrations
Integrates with popular data science tools such as Pandas. Saving you time to help you clean your datasets with little code.
scikit-learn and Pandera integrations are currently under development.
Example
>>> import pandas as pd
>>> from symconstraints import Constraints
>>> from symconstraints.pandas import symbols, check, set_invalid_all, impute
>>> from sympy import Eq
>>> df = pd.DataFrame(
... {
... "height": [5, 6, 8, 9],
... "width": [3, 5, 7, None],
... "area": [14, 30, None, 18],
... },
... dtype=float,
... )
>>> height, width, area = symbols(df, ["height", "width", "area"])
>>> constraints = Constraints([height > width, Eq(area, width * height)])
>>> check_result = check(constraints, df)
>>> df = set_invalid_all(check_result, df)
>>> df
height width area
0 NaN NaN NaN
1 6.0 5.0 30.0
2 8.0 7.0 NaN
3 9.0 NaN 18.0
>>> imputed_df = impute(constraints, df)
>>> imputed_df
height width area
0 NaN NaN NaN
1 6.0 5.0 30.0
2 8.0 7.0 56.0
3 9.0 2.0 18.0
License
symconstraints is distributed under the terms of the MIT license.
Metadata
Release files for symconstraints 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| symconstraints-0.0.1.tar.gz | 12.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| symconstraints-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.4 kB
Release files / symconstraints-0.0.1.tar.gz
| Download URL | symconstraints-0.0.1.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29c9a9bbfb44a1f5655decc2566b503140bc9da7b2612923fbcdcf474e163985
|
|
BLAKE2b-256 checksum How to use checksums |
6eaf5525cc0544da278471c5136c35e8f288bc423a66572e2a1393db2ce6c2ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / symconstraints-0.0.1-py3-none-any.whl
| Download URL | symconstraints-0.0.1-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82236e579f765e2d49cae6af6abedbe0371bde3ce5cc5e162d9c985d2d9cd762
|
|
BLAKE2b-256 checksum How to use checksums |
5dcedc93b71d30b77540e085c11562416fc3d567d2bd1ea971e9b72187c59113
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for symconstraints 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.