fix(rdkit): avoid deprecated explicit valence API#969
fix(rdkit): avoid deprecated explicit valence API#969njzjz-bot wants to merge 5 commits intodeepmodeling:masterfrom
Conversation
Prefer the new RDKit explicit valence API when available and fall back to the legacy method for older RDKit versions. Add a focused unit test that covers both code paths without requiring RDKit at test time. Authored by OpenClaw (model: gpt-5.4)
for more information, see https://pre-commit.ci
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 39 minutes and 38 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughModified Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this PR will not alter performance
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #969 +/- ##
==========================================
- Coverage 86.70% 86.67% -0.03%
==========================================
Files 86 86
Lines 8039 8045 +6
==========================================
+ Hits 6970 6973 +3
- Misses 1069 1072 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_rdkit_sanitize.py (1)
8-12: Optional: consider importing via the package instead of loading the file by path.Loading
sanitize.pyviaimportlib.util.spec_from_file_locationbypassesdpdata.rdkit.__init__and the normal package import path, which is unusual relative to the rest of the suite (e.g.,tests/test_gaussian_driver.pyusesimportlib.util.find_spec+@unittest.skipIfto gate on optional deps). Sinceget_explicit_valenceitself doesn't require rdkit at import time, a plainfrom dpdata.rdkit.sanitize import get_explicit_valence(optionally guarded) would be more conventional and avoid theassert SPEC.loader is not Nonedance. Not blocking.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_rdkit_sanitize.py` around lines 8 - 12, The test currently loads sanitize.py by path using MODULE_PATH, SPEC and SPEC.loader.exec_module(sanitize); replace this with a normal package import to avoid bypassing dpdata.rdkit.__init__: import the symbol directly (e.g. from dpdata.rdkit.sanitize import get_explicit_valence) and, if you need to guard for optional rdkit, use importlib.util.find_spec("rdkit") or a try/except ImportError and apply unittest.skipIf or skip the test accordingly rather than using importlib.util.spec_from_file_location and the SPEC.loader assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_rdkit_sanitize.py`:
- Around line 71-82: The test test_falls_back_to_legacy_api_when_new_api_missing
can silently succeed by accidentally using a real rdkit submodule cached at
sys.modules['rdkit.Chem']; when patching sys.modules to fake a top-level rdkit
you must also ensure sys.modules['rdkit.Chem'] is patched (either removed or set
to a harmless fake) so Python cannot fall back to a real submodule; update the
test to set sys.modules['rdkit.Chem'] to the same fake (or to None/placeholder)
alongside sys.modules['rdkit'] when exercising sanitize.get_explicit_valence to
guarantee the legacy-api fallback is actually being tested.
---
Nitpick comments:
In `@tests/test_rdkit_sanitize.py`:
- Around line 8-12: The test currently loads sanitize.py by path using
MODULE_PATH, SPEC and SPEC.loader.exec_module(sanitize); replace this with a
normal package import to avoid bypassing dpdata.rdkit.__init__: import the
symbol directly (e.g. from dpdata.rdkit.sanitize import get_explicit_valence)
and, if you need to guard for optional rdkit, use
importlib.util.find_spec("rdkit") or a try/except ImportError and apply
unittest.skipIf or skip the test accordingly rather than using
importlib.util.spec_from_file_location and the SPEC.loader assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c35f8b2a-9824-4e42-a0bc-6476550c80cc
📒 Files selected for processing (2)
dpdata/rdkit/sanitize.pytests/test_rdkit_sanitize.py
There was a problem hiding this comment.
Pull request overview
Updates RDKit valence handling to avoid using a deprecated API while keeping compatibility with older RDKit versions, and adds a unit test to exercise both code paths without requiring RDKit at test time.
Changes:
- Use
Atom.GetValence(Chem.ValenceType.EXPLICIT)when available, with fallback toAtom.GetExplicitValence(). - Improve verbose inconsistency message to include which valence API was used.
- Add a new unit test for the preferred (new) API path and the legacy fallback path using mocked RDKit modules.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dpdata/rdkit/sanitize.py |
Prefer non-deprecated RDKit explicit valence API with a compatibility fallback; update verbose message accordingly. |
tests/test_rdkit_sanitize.py |
Add RDKit-free unit tests using mocks to cover new-API and fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed the review comments in 7a7f862:
I could only do a local syntax check here because this machine does not currently have the full test deps installed, but CI on the PR should verify the RDKit-backed path. |
Problem
Atom.GetExplicitValence()in recent releases, which makes dpdata CI emit a deprecation warning.dpdata.rdkit.sanitize.get_explicit_valence()still called the deprecated API directly.Change
Atom.GetValence(Chem.ValenceType.EXPLICIT)when available, with a fallback toAtom.GetExplicitValence()for compatibility with older RDKit versions.Notes
DEPRECATION WARNING: please use GetValence(Chem.ValenceType.EXPLICIT) instead#968.python3 -m unittest tests/test_rdkit_sanitize.pyAuthored by OpenClaw (model: gpt-5.4)
Summary by CodeRabbit
Release Notes
Chores
Tests