You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
timezone-aware coords do not build after version 0.8.0 #898
I have confirmed this bug exists on the lastest release of Linopy.
I have confirmed this bug exists on the current master branch of Linopy.
Issue Description
since version 0.8.0, a model fails to build if timezone-aware time coords are used. The regression happens in add_variables(), where a strict broadcast_to_coords() validation was introduced by #732.
The expected and actual indexes for validation are constructed differently:
expected_idx = pd.Index(coord_values) # this happens in alignment.py::_as_index() helper
actual_idx = arr.coords[dim].to_index()
For a timezone-aware xarray DataArray, the first conversion produces an object index of integer nanoseconds, while the second produces the original timezone-aware pandas DatetimeIndex. The equality check therefore fails even though both coordinates originate from the same input.
validation should pass and model should be created with the timezone-aware coord. A minimal fix could be to adapt _as_index() helper in alignment.py to call to_index() for DataArrays, which retrieves the pandas index directly (as compared to the pd.Index constructor, which goes through numpy arrays, deleting the timezone in the process).
Activity