Skip to main content

pandera-chem: chemistry checks for Pandera. Validate tables of molecules with RDKit, and quarantine the bad rows with their reasons.

Tests Python 3.11, 3.12, 3.13 Ruff MIT licence Cite

Chemistry checks for Pandera. Validate tables of molecules with RDKit inside the data pipeline you already have, and set the bad rows aside with the reason each one failed, instead of crashing or losing them.

Why

Chemical tables arrive with problems a type check cannot see: SMILES that RDKit cannot read, salts and mixtures, unexpected elements, charged forms, missing stereochemistry, and the same molecule twice under different SMILES. The usual fix is a loop that drops what fails to parse, and the records vanish with no reason recorded.

pandera-chem turns those problems into Pandera checks, so they sit in the same schema as your other rules (types, ranges, units), and adds split(), which keeps the good rows, sets the bad ones aside with their reasons, and gives you counts that must add up.

Install

pip install pandera-chem

or uv add pandera-chem. It needs Python 3.11 or newer, and installs Pandera and RDKit.

Example

A table of measured compounds, with a few of the problems real data has:

import pandas as pd
import pandera.pandas as pa

import pandera_chem as pc

table = pd.DataFrame(
    {
        "compound_id": ["C1", "C2", "C3", "C4", "C5", "C6", "C7"],
        "smiles": [
            "CC(=O)Oc1ccccc1C(=O)O",  # aspirin
            "OC(=O)c1ccccc1OC(C)=O",  # aspirin again, written differently
            "c1ccc2ccccc2c1",  # naphthalene
            "c1ccccc",  # a ring that never closes
            "C[Se]c1ccccc1",  # selenium
            "CC(=O)[O-].[Na+]",  # a salt
            "CC(C)Cc1ccc(cc1)C(C)C(=O)O",  # ibuprofen, stereocentre not given
        ],
        "pic50": [5.2, 5.4, 4.1, 6.0, 5.0, 3.2, 15.0],
    }
)

schema = pa.DataFrameSchema(
    {
        "compound_id": pa.Column(str, unique=True),
        "smiles": pa.Column(
            str,
            [
                pc.valid_smiles(),
                pc.allowed_elements(),
                pc.single_fragment(),
                pc.unique_molecules(),
                pc.stereo_defined(raise_warning=True),  # a warning, not a failure
            ],
        ),
        "pic50": pa.Column(float, pa.Check.in_range(0, 14)),
    }
)

result = pc.split(table, schema)
print(result.report)
print()
print(result.quarantined[["compound_id", "reasons"]].to_string(index=False))
print()
print(pc.problems("c1ccccc"))

It prints:

7 rows in: 2 valid, 5 quarantined
       2  smiles: allowed_elements
       1  smiles: valid_smiles
       1  smiles: single_fragment
       1  smiles: unique_molecules
       1  pic50: in_range(0, 14)
  warning: Column 'smiles' failed element-wise validator number 4: <Check stereo_defined> failure cases: CC(C)Cc1ccc(cc1)C(C)C(=O)O

compound_id                                           reasons
         C2                          smiles: unique_molecules
         C4                              smiles: valid_smiles
         C5                          smiles: allowed_elements
         C6 smiles: allowed_elements; smiles: single_fragment
         C7                            pic50: in_range(0, 14)

['the SMILES could not be read']
  • result.valid: the rows that passed (aspirin and naphthalene), ready for the next step.
  • result.quarantined: the rest, unchanged, with a reasons column. Save it, fix the records and run them again.
  • result.report: the counts. result.report.reconciles is True when every row is accounted for (rows in = valid + quarantined); log it with every run.
  • Ibuprofen passed with a warning: its stereocentre is not given, which you may accept for a racemate. Any check becomes a warning with raise_warning=True.

The checks work in plain Pandera too: schema.validate(table) raises an error naming the check that failed, as Pandera always does.

The checks

On a column of SMILES:

Check Fails when
valid_smiles() RDKit cannot read or sanitise the SMILES (syntax, valence, aromaticity)
allowed_elements(elements=ORGANIC) an atom is not in the allowed set (default: H, B, C, N, O, F, P, S, Cl, Br, I)
single_fragment() the record holds more than one molecule: a salt, a solvent or a mixture
neutral() the net formal charge is not zero (charges that cancel, as in a nitro group, are fine)
stereo_defined() a stereocentre or stereogenic double bond has no configuration given
heavy_atoms(min_value, max_value) the largest fragment has too few or too many heavy atoms
mol_weight(max_value, min_value=0) the largest fragment is too light or too heavy (g/mol)
no_substructures({"name": "SMARTS", ...}) the molecule contains one of the given groups
unique_molecules() the same molecule appeared in an earlier row, even as a different SMILES

On InChIKeys:

Check Fails when
inchikey_format() the value is not shaped like a standard InChIKey
inchikey_matches("smiles", "inchikey") (table-wide) a row's InChIKey is not the one its SMILES gives

Helpers: pc.problems(smiles) says why a SMILES cannot be read, in RDKit's words; pc.inchikey(smiles) gives its standard InChIKey; pc.clear_cache() frees the parsed molecules.

How it works

  • One reason per problem. Only valid_smiles() fails a SMILES that cannot be read; every other check lets it pass. A broken record is reported once, as unreadable, not under every check.
  • Each SMILES is read once. All the checks share one cache of parsed molecules, so five checks on a column cost about one parse per distinct SMILES. Call pc.clear_cache() after a very large table.
  • Pandera's own options work. Every check accepts them: raise_warning=True, n_failure_cases=10 and so on.
  • Nothing is changed. pandera-chem checks molecules; it never alters them. To repair records (strip salts, neutralise charges, pick one tautomer), use RDKit's MolStandardize or the ChEMBL structure pipeline first, then check the result. For a web page that validates an uploaded file, see ChemAudit.

Roadmap

Ideas for later versions; suggest one.

  • Polars data frames, which Pandera also supports.
  • The ChEMBL structure checker as a check, with a penalty threshold.
  • Pydantic types for single records (SMILES, InChIKey).
  • Checks registered by name, so schemas can be written in YAML.

Learn the ideas behind it

pandera-chem grew out of the free course Data Engineering for Cheminformatics, which builds these checks by hand: validating molecules in Module 6, the quarantine in Module 10, and validating whole tables with Pydantic and Pandera in Module 12.

Contributing

Bug reports, suggestions and pull requests are welcome: see CONTRIBUTING.md. Everyone taking part follows the code of conduct. The example above is run by the tests, which check that this README shows what it really prints.

Citing

If pandera-chem helps your research, please cite it: GitHub's Cite this repository button (from CITATION.cff) gives the reference in APA and BibTeX.

Licence

MIT (LICENSE). Made by Monstrous Data.

Metadata

Release files for pandera-chem 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandera-chem 0.1.0
File Size Uploaded Provenance Actions
pandera_chem-0.1.0.tar.gz 11.9 kB With provenance Details for pandera_chem-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pandera-chem 0.1.0
File Interpreter ABI Platform Actions
pandera_chem-0.1.0-py3-none-any.whl Python 3 none any Details for pandera_chem-0.1.0-py3-none-any.whl

Total release size: 25.2 kB

Release files / pandera_chem-0.1.0.tar.gz

Download URL pandera_chem-0.1.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5852273ba16e363b2198c6525f24c96fbdabd74872c138c064bb82545bda4247
BLAKE2b-256 checksum
How to use checksums
58d0d64fd232730432b6c4ba26e220185f76899cc8c466d005e906ad9a906cda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / pandera_chem-0.1.0-py3-none-any.whl

Download URL pandera_chem-0.1.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ea0605629debd2361d86d834e998ab2f5d8acce46423a79fab34fb71f8ec850
BLAKE2b-256 checksum
How to use checksums
251e26162161bd8f0c82f8c9de1f7cc4322249c6718b727c9143e57536a55abd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for pandera-chem 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pandera_chem-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page