Skip to content

fix: convert sun altitudes to numpy array for local time mode#34

Closed
themavik wants to merge 1 commit into
bellingcat:mainfrom
themavik:fix-local-time-pandas-typeerror
Closed

fix: convert sun altitudes to numpy array for local time mode#34
themavik wants to merge 1 commit into
bellingcat:mainfrom
themavik:fix-local-time-pandas-typeerror

Conversation

@themavik

Copy link
Copy Markdown

Summary

When using time_format='local', pd.to_datetime() returns a DatetimeIndex which propagates through suncalc.get_position(). The resulting pos_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:

TypeError: Index does not support mutable operations

This only affects the local time path. The utc path works because it passes a single datetime object rather than a DatetimeIndex.

Changes

Wrap pos_obj["altitude"] with np.asarray() to ensure the altitude values are a plain mutable numpy array, regardless of what suncalc returns.

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 correctly
  • time_format='local' with sun altitude angle: no longer crashes

Fixes #31

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>
@GalenReich

Copy link
Copy Markdown
Collaborator

Thanks for this PR, I've just merged #32 which dealt with the same issue.

@GalenReich GalenReich closed this Feb 13, 2026
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.

ShadowFinderColab TypeError

2 participants