docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759) - #920
docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759)#920chethanuk wants to merge 1 commit into
Conversation
STYLEGUIDE.md recommended `from data_designer.lazy_heavy_imports import pd, np`, which is an attribute read against the PEP-562 facade and therefore imports pandas eagerly while the consuming module is still importing. Only `import data_designer.lazy_heavy_imports as lazy` + `lazy.pd` stays lazy, which is what lazy_heavy_imports.py's docstring already requires and what test_lazy_imports.py already asserts. Rewrites the four STYLEGUIDE.md blocks to the alias form, gives each snippet a call site so the TYPE_CHECKING imports are motivated, and adds `from __future__ import annotations` so the annotations resolve at def-time. Converts scripts/benchmarks/benchmark_engine_v2.py, the tree's only remaining user of the banned form. Also extends test_lazy_imports.py's guard to cover scripts/, since it previously only globbed packages/*/src and missed scripts/benchmarks/benchmark_engine_v2.py's banned from-import form. Signed-off-by: ChethanUK <chethanuk@outlook.com>
Linked Issue CheckIssue #759 has not been triaged yet. A maintainer needs to review You can continue working on the PR in the meantime. The check will |
|
Thank you for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text: I have read the DCO document and I hereby sign the DCO. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot. |
Greptile SummaryThis PR corrects the lazy-heavy-import guidance and aligns the remaining benchmark usage with the genuinely deferred import pattern.
|
| Filename | Overview |
|---|---|
| STYLEGUIDE.md | Replaces eager from-import examples with accurate lazy module-alias guidance and concrete call sites. |
| packages/data-designer/tests/test_lazy_imports.py | Adds a correctly rooted recursive guard against eager lazy-facade imports in Python scripts. |
| scripts/benchmarks/benchmark_engine_v2.py | Preserves benchmark behavior while deferring NumPy and pandas imports until their first runtime use. |
Reviews (1): Last reviewed commit: "docs: teach the lazy import form that is..." | Re-trigger Greptile
📋 Summary
STYLEGUIDE.mdandlazy_heavy_imports.pyrecommend opposite import forms for lazy-loadingheavy dependencies.
from data_designer.lazy_heavy_imports import pd, npis an attribute readagainst the module's PEP-562
__getattr__facade, so it fires while the consuming module isstill importing and pandas loads eagerly — the facade buys nothing. Only
import data_designer.lazy_heavy_imports as lazy+lazy.pdstays lazy, which is what themodule's own docstring already requires and what
test_lazy_imports.pyalready asserts. Thisaligns the guide to the form that actually works.
🔗 Related Issue
Fixes #759
🔄 Changes
STYLEGUIDE.md: rewrite the four blocks that taught thefrom ... import pd, npform to usethe
import ... as lazy/lazy.pdform instead. Each example gains a call site andfrom __future__ import annotationsso the snippets are runnable modules rather thanillustrations that raise
NameErrorif copy-pasted.scripts/benchmarks/benchmark_engine_v2.py: convert the tree's only remaining user of thebanned form to the alias pattern.
packages/data-designer/tests/test_lazy_imports.py: addtest_scripts_avoid_from_lazy_heavy_imports_pattern, extending the existingpackages/*/src/**guard toscripts/**— the gap that let the benchmark script drift.🧪 Testing
make test—test_lazy_imports.py: 1 failed, 4 passed before the fix (fails onbenchmark_engine_v2.py); 5 passed aftermake lint/make format-check— all checks passedmake test-interface— 1119 passed, 1 skipped, 1 pre-existing failure(
test_import_performance, an environmentalmake perf-importtimeout under machine load,reproduced identically on
mainwith none of this branch's changes applied)dataset_hash✅ Checklist
git commit -sNote: issue #759 does not currently carry the
triagedlabel; the upstreamlinked-issue workflow may gate on that independent of this PR.
Fixes #759