import pandas as pdfrom spotforecast2_safe.utils.convert_to_utc import convert_to_utc# Scenario 2: non-UTC tz-aware index (US/Eastern) → converted to UTCidx = pd.date_range("2022-06-01", periods=3, freq="h", tz="US/Eastern")df_eastern = pd.DataFrame({"value": [10, 20, 30]}, index=idx)result_eastern = convert_to_utc(df_eastern, timezone=None)print("US/Eastern → UTC result:")print(result_eastern)assertstr(result_eastern.index.tz) =="UTC"# US/Eastern is UTC-4 in June (EDT), so 00:00 Eastern = 04:00 UTCassert result_eastern.index[0] == pd.Timestamp("2022-06-01 04:00:00", tz="UTC")
US/Eastern → UTC result:
value
2022-06-01 04:00:00+00:00 10
2022-06-01 05:00:00+00:00 20
2022-06-01 06:00:00+00:00 30
to_utc_timestamp
utils.convert_to_utc.to_utc_timestamp(value)
Coerce a string or Timestamp to a UTC-aware pandas.Timestamp.
Strings are parsed with utc=True; existing Timestamps are returned unchanged. This deduplicates the same three-line pattern repeated across public feature builders in this package.