Skip to content

Conflicting guidance on lazy heavy imports #759

Description

@rparkr

Summary

STYLEGUIDE.md and lazy_heavy_imports.py give conflicting guidance on importing heavy third-party libraries. The two sources should be aligned to clarify the expected pattern to use when writing new code.

The style guide

STYLEGUIDE.md notes that large dependencies should be lazy-loaded by importing the library alias from the data_designer.lazy_heavy_imports module:

DataDesigner/STYLEGUIDE.md

Lines 145 to 147 in 7c2c15e

# Use lazy loading with IDE support
from typing import TYPE_CHECKING
from data_designer.lazy_heavy_imports import pd, np

STYLEGUIDE.md also explains that any newly added heavy dependencies (e.g., your_lib) should use that same pattern:

from data_designer.lazy_heavy_imports import your_lib

The module docstring

In lazy_heavy_imports.py, the docstring warns against the exact pattern that STYLEGUIDE.md recommended:

Important:
Avoid `from data_designer.lazy_heavy_imports import pd`.
That import style resolves the attribute immediately and eagerly imports the heavy dependency.

Proposed resolution

Align both documentation sources to the same pattern to avoid confusion about which method is preferable, i.e., either importing the library alias from lazy_heavy_imports:

from data_designer.lazy_heavy_imports import pd, np 

or importing the lazy_heavy_imports module and accessing its attributes at runtime:

import data_designer.lazy_heavy_imports as lazy

# ...when needed in the code:
df = lazy.pd.DataFrame(...)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triagedIssue reviewed and approved by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions