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 (in a notebook: !pip install 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.

Next: the usage guide shows checking strictly, running pandera-chem in a pipeline (saving the quarantine, logging, stopping a bad run), rules for a screening library, tables with InChIKeys, and writing a check of your own.

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. Every example in this README and the usage guide is run by the tests, which check that the page 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.1

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.1
File Size Uploaded Provenance Actions
pandera_chem-0.1.1.tar.gz 12.2 kB With provenance Details for pandera_chem-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 25.8 kB

Release files / pandera_chem-0.1.1.tar.gz

Download URL pandera_chem-0.1.1.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
060217a8a68af240f0f9b38b5635bf7af2057aac63bbe1749519fdbdc2600c91
BLAKE2b-256 checksum
How to use checksums
d37d1b08099aae9683ccaca8ee3e3f38c21025af312cdec45fb1b203be8a7290
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.1-py3-none-any.whl

Download URL pandera_chem-0.1.1-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ba93710631ac99db1ee870946a60f67d96cc410388d7269fe75929eefc8e81e
BLAKE2b-256 checksum
How to use checksums
639a5722d255f515d34f79917096e9155674603f5a553a5beaf7c73deea17998
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.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.

Full provenance

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

Select from 2 files

Attestation for pandera_chem-0.1.1.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