Move desimodel footprint imports to just-in-time in io.py - #894
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Update just-in-time imports in io.py
Move desimodel footprint imports to just-in-time in io.py
Jul 23, 2026
sbailey
marked this pull request as ready for review
July 27, 2026 17:54
sbailey
approved these changes
Jul 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents import desitarget.io from unconditionally importing desimodel (and triggering desimodel data-not-installed warnings) by moving desimodel.footprint imports to just-in-time imports inside the tile-reading functions that actually use them.
Changes:
- Removed the module-level
from desimodel.footprint import is_point_in_desi, tiles2piximport. - Added deferred (function-scope) imports of
is_point_in_desi/tiles2pixwithin the three tile-based readers that use them. - Kept non-tile call paths free of
desimodelimports, matching the intent of issue #893.
Comments suppressed due to low confidence (2)
py/desitarget/io.py:4069
- These comments suggest
desimodelis a "required dependency", but this code is actually deferring an optional dependency import until theshape == 'tiles'path is used. Reword (and consider dropping the redundant note) to clarify the intent is avoiding desimodel import at module import time.
# import desimodel only when needed to avoid required dependency
# Note: `is_point_in_desi` will be used below
py/desitarget/io.py:4253
- Comment wording is misleading:
desimodelis still required at runtime for tile-based filtering, but the intent is to avoid importingdesimodelwhendesitarget.iois imported. Reword to clarify this is a deferred import of an optional dependency.
# import only when needed to avoid desimodel required dependency
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@moustakas please confirm that this branch fixed your fastspecfit case reported in #894 . Tests are failing due to inability to download DESI_SURVEYOPS shapshot from data.desi.lbl.gov . |
Member
|
Yes, looks good, thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Importing
desitarget.iounconditionally triggered adesimodeldata-not-installed warning even when no tile-related functions were called, becausefrom desimodel.footprint import is_point_in_desi, tiles2pixsat at module level.Changes
is_point_in_desiandtiles2pixfromdesimodel.footprintread_targets_in_tiles_quick— imported unconditionally at function entry (both symbols always used)read_targets_in_quick— imported insideif shape == 'tiles':branch (only needed for that shape)read_targets_in_tiles— imported before first use (both symbols used on all non-early-return paths)Python's import cache (
sys.modules) means the deferred import has no repeated overhead after the first call.