diff --git a/exchange_calendars/calendar_helpers.py b/exchange_calendars/calendar_helpers.py index 88d8b606..8df5a6bd 100644 --- a/exchange_calendars/calendar_helpers.py +++ b/exchange_calendars/calendar_helpers.py @@ -680,7 +680,7 @@ def trading_index(self) -> pd.DatetimeIndex: index = self._trading_index() if self.has_break: index.sort() - index = pd.DatetimeIndex(index, tz="UTC") + index = pd.DatetimeIndex(index, tz=pytz.UTC) return self.curtail_for_times(index) @contextlib.contextmanager @@ -718,7 +718,7 @@ def trading_index_intervals(self) -> pd.IntervalIndex: else: raise errors.IntervalsOverlapError() - left = pd.DatetimeIndex(left, tz="UTC") - right = pd.DatetimeIndex(right, tz="UTC") + left = pd.DatetimeIndex(left, tz=pytz.UTC) + right = pd.DatetimeIndex(right, tz=pytz.UTC) index = pd.IntervalIndex.from_arrays(left, right, self.closed) return self.curtail_for_times(index) diff --git a/exchange_calendars/pandas_extensions/offsets.py b/exchange_calendars/pandas_extensions/offsets.py index 9d2e9449..ef8626a1 100644 --- a/exchange_calendars/pandas_extensions/offsets.py +++ b/exchange_calendars/pandas_extensions/offsets.py @@ -149,7 +149,7 @@ def _apply(self, other): bday, interval = self._custom_business_day_for( other, remaining, with_interval=True ) - result = bday.apply(other) + result = bday + other while not interval.left <= result <= interval.right: previous_other = other if result < interval.left: diff --git a/exchange_calendars/utils/pandas_utils.py b/exchange_calendars/utils/pandas_utils.py index 78fcab13..80b4206b 100644 --- a/exchange_calendars/utils/pandas_utils.py +++ b/exchange_calendars/utils/pandas_utils.py @@ -117,7 +117,7 @@ def longest_run(ser: pd.Series) -> pd.Index: ... | ((ser >= 55) & (ser < 61)) ... ) >>> longest_run(bv) - Int64Index([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], dtype='int64') + Index([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], dtype='int32') >>> pd.testing.assert_index_equal(longest_run(bv), ser.index[30:41]) """ # group Trues by only adding to sum when value False. diff --git a/tests/test_calendar_helpers.py b/tests/test_calendar_helpers.py index d060b5e5..57e7f4e1 100644 --- a/tests/test_calendar_helpers.py +++ b/tests/test_calendar_helpers.py @@ -639,7 +639,7 @@ def bounds(start: pd.Series, end: pd.Series, force: bool, align: pd.Timedelta): if curtail and not (force_close and force_break_close): indices = lower_bounds.argsort() - lower_bounds.sort_values(inplace=True) + lower_bounds = lower_bounds.sort_values() upper_bounds = upper_bounds[indices] curtail_mask = upper_bounds > lower_bounds.shift(-1) if curtail_mask.any(): diff --git a/tests/test_exchange_calendar.py b/tests/test_exchange_calendar.py index 030d0fc5..88c8c717 100644 --- a/tests/test_exchange_calendar.py +++ b/tests/test_exchange_calendar.py @@ -11,6 +11,7 @@ # limitations under the License. from __future__ import annotations +import datetime import functools import itertools import pathlib @@ -181,7 +182,6 @@ def get_csv(name: str) -> pd.DataFrame: path, index_col=0, parse_dates=[0, 1, 2, 3, 4], - infer_datetime_format=True, ) # Necessary for csv saved prior to v4.0 if df.index.tz is not None: @@ -190,6 +190,8 @@ def get_csv(name: str) -> pd.DataFrame: for col in df: if df[col].dt.tz is None: df[col] = df[col].dt.tz_localize(UTC) + elif df[col].dt.tz is datetime.timezone.utc: + df[col] = df[col].dt.tz_convert(UTC) return df @@ -2146,7 +2148,7 @@ def late_opens( date_to = pd.Timestamp.max dtis: list[pd.DatetimeIndex] = [] # For each period over which a distinct open time prevails... - for date_from, time_ in s.iteritems(): + for date_from, time_ in s.items(): opens = ans.opens[date_from:date_to] sessions = opens.index td = pd.Timedelta(hours=time_.hour, minutes=time_.minute) @@ -2186,7 +2188,7 @@ def early_closes( date_to = pd.Timestamp.max dtis: list[pd.DatetimeIndex] = [] - for date_from, time_ in s.iteritems(): + for date_from, time_ in s.items(): closes = ans.closes[date_from:date_to] # index to tz-naive sessions = closes.index td = pd.Timedelta(hours=time_.hour, minutes=time_.minute) @@ -3837,14 +3839,18 @@ def unite(dtis: list[pd.DatetimeIndex]) -> pd.DatetimeIndex: else: ends = ans.closes # index for a 'left' calendar, add end so evaluated as if 'both' - index = index.append(pd.DatetimeIndex([ends[session]])) + index = index.append( + pd.DatetimeIndex([ends[session]], tz=pytz.UTC) + ) index = index[::mins] # only want every period if not index[-1] == ends[session]: # if period doesn't coincide with end, add right side of # last interval which lies beyond end. last_indice = index[-1] + period - index = index.append(pd.DatetimeIndex([last_indice])) + index = index.append( + pd.DatetimeIndex([last_indice], tz=pytz.UTC) + ) dtis.append(index) both_index = unite(dtis)