fix: convert sun altitudes to numpy array for local time mode#34
Closed
themavik wants to merge 1 commit into
Closed
fix: convert sun altitudes to numpy array for local time mode#34themavik wants to merge 1 commit into
themavik wants to merge 1 commit into
Conversation
When time_format='local', pd.to_datetime() returns a DatetimeIndex which propagates through suncalc.get_position(), causing pos_obj["altitude"] to return a pandas object backed by an immutable Index. Subsequent item assignment (shadow_lengths[...] = np.nan) then fails with TypeError: Index does not support mutable operations. Wrap the altitude values with np.asarray() to ensure they are a plain numpy array regardless of the pandas version or input type. The UTC path is unaffected since it passes a single datetime. Fixes #31 Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
|
Thanks for this PR, I've just merged #32 which dealt with the same issue. |
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.
Summary
When using
time_format='local',pd.to_datetime()returns aDatetimeIndexwhich propagates throughsuncalc.get_position(). The resultingpos_obj["altitude"]is a pandas object backed by an immutable Index. Downstream code then tries item assignment (shadow_lengths[valid_sun_altitudes <= 0] = np.nan) which fails with:This only affects the
localtime path. Theutcpath works because it passes a singledatetimeobject rather than aDatetimeIndex.Changes
Wrap
pos_obj["altitude"]withnp.asarray()to ensure the altitude values are a plain mutable numpy array, regardless of whatsuncalcreturns.Test Plan
time_format='utc': behavior unchanged (np.asarray on an already-numpy array is a no-op)time_format='local'with object height/shadow length: no longer crashes, shadow map renders correctlytime_format='local'with sun altitude angle: no longer crashesFixes #31