Skip to content

Using timezone aware datetime in coords causes a warning #451

@etr-iet

Description

@etr-iet

Version Checks (indicate both or one)

  • 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

Observed behavior

When using a timezone-aware pandas.DatetimeIndex as a coordinate, and using multiplication of the variable and some pandas series, a warning is raised

UserWarning: coords for dimension(s) ['time'] is not aligned with the pandas object. Previously, the indexes of the pandas were ignored and overwritten in these cases. Now, the pandas object's coordinates are taken considered for alignment.

Reproducible Example

from linopy import Model
import pandas as pd
from datetime import datetime
from zoneinfo import ZoneInfo

m = Model()

exogenous_series0 = pd.Series(0, 
    index=pd.DatetimeIndex(
        pd.date_range(start=datetime(2025,1,1), freq="15min", periods=4, tz=ZoneInfo("Australia/Sydney"), name="time")
    )
)

time = exogenous_series0.index.copy()

exogenous_series1 = pd.Series(1, index=time)

var1 = m.add_variables(coords=[time], name="var1")

m.add_constraints(0 <= var1*exogenous_series1) ## This causes a warning

m.add_constraints(0 <= var1 + exogenous_series1) ## This does NOT cause a warning

Expected Behavior

I expected to be able to use a timezone-aware pandas.DatetimeIndex as a coordinate. However, doing so causes a warning about alignment

Installed Versions

Linopy 0.53

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions