Skip to content

docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759) - #920

Open
chethanuk wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
chethanuk:fix/issue-759-ship
Open

docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759)#920
chethanuk wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
chethanuk:fix/issue-759-ship

Conversation

@chethanuk

Copy link
Copy Markdown

📋 Summary

STYLEGUIDE.md and lazy_heavy_imports.py recommend opposite import forms for lazy-loading
heavy dependencies. from data_designer.lazy_heavy_imports import pd, np is an attribute read
against the module's PEP-562 __getattr__ facade, so it fires while the consuming module is
still importing and pandas loads eagerly — the facade buys nothing. Only
import data_designer.lazy_heavy_imports as lazy + lazy.pd stays lazy, which is what the
module's own docstring already requires and what test_lazy_imports.py already asserts. This
aligns the guide to the form that actually works.

🔗 Related Issue

Fixes #759

🔄 Changes

  • STYLEGUIDE.md: rewrite the four blocks that taught the from ... import pd, np form to use
    the import ... as lazy / lazy.pd form instead. Each example gains a call site and
    from __future__ import annotations so the snippets are runnable modules rather than
    illustrations that raise NameError if copy-pasted.
  • scripts/benchmarks/benchmark_engine_v2.py: convert the tree's only remaining user of the
    banned form to the alias pattern.
  • packages/data-designer/tests/test_lazy_imports.py: add
    test_scripts_avoid_from_lazy_heavy_imports_pattern, extending the existing
    packages/*/src/** guard to scripts/** — the gap that let the benchmark script drift.

🧪 Testing

  • make testtest_lazy_imports.py: 1 failed, 4 passed before the fix (fails on
    benchmark_engine_v2.py); 5 passed after
  • make lint / make format-check — all checks passed
  • make test-interface — 1119 passed, 1 skipped, 1 pre-existing failure
    (test_import_performance, an environmental make perf-import timeout under machine load,
    reproduced identically on main with none of this branch's changes applied)
  • Benchmark script re-run at a fixed seed, before and after conversion: identical
    dataset_hash

✅ Checklist

  • Follows commit message conventions
  • Commits are signed off (DCO) — squashed to one commit, git commit -s
  • Architecture docs updated — N/A (docs/test/script only, no architecture change)

Note: issue #759 does not currently carry the triaged label; the upstream
linked-issue workflow may gate on that independent of this PR.

Fixes #759

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>
@chethanuk
chethanuk requested a review from a team as a code owner September 5, 2026 05:25
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Thank you for your submission! We ask that you all 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.


1 out of 2 committers have signed the DCO.
✅ (nabinchha)[https://github.com/nabinchha]
@chethanuk
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no actionable correctness or repository-rule violations identified.

Summary

  • Updates STYLEGUIDE.md examples to use import data_designer.lazy_heavy_imports as lazy.
  • Converts benchmark NumPy and pandas accesses to the lazy module facade.
  • Adds a regression test preventing the eager from-import pattern under scripts/**.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/issue-759-s..."

@github-actions

Copy link
Copy Markdown
Contributor

Issue #759 received the triaged label. The linked issue check is being re-evaluated.

@nabinchha

Copy link
Copy Markdown
Contributor

Thanks for putting this together, @chethanuk!

Summary

This aligns STYLEGUIDE.md with the lazy facade's actual PEP 562 behavior, converts the remaining benchmark-script caller to the module-alias form, and extends the regression guard to scripts/**/*.py. The implementation matches the PR description and the resolution requested in issue #759.

Before merge, @chethanuk, please address the DCO Assistant request by following the bot's instructions to acknowledge the DCO, then comment recheck if the check does not rerun automatically.

Findings

No findings.

What Looks Good

  • The revised examples show both deferred annotations and real lazy.<alias> call sites, so the recommended pattern is clear and directly usable.
  • Updating the benchmark script alongside the documentation removes the known inconsistency rather than leaving an in-tree counterexample.
  • The new script scan complements the existing runtime-source guard, and the focused lazy-import tests pass end to end.

Verdict

Ship it — the code changes are ready; merge remains pending the DCO acknowledgment requested above.


This review was generated by an AI assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conflicting guidance on lazy heavy imports

2 participants