Skip to content

Commit

Permalink
test: Adapt the CustomTimeseries test fixture
Browse files Browse the repository at this point in the history
Comparison of tz-naive and tz-aware datetime-like objects
has been removed in Pandas 2.0.

See: pandas-dev/pandas#49492

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
  • Loading branch information
jjerphan committed Jul 11, 2023
1 parent e39d7a2 commit 5b7c41c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ def __init__(self, wrapped: pd.DataFrame, *, with_timezone_attr: bool, timezone_

def __getitem__(self, item):
if isinstance(item, slice):
open_ended = slice(item.start + timedelta(microseconds=1), item.stop - timedelta(microseconds=1), item.step)
# Comparing datetimes with timezone to datetimes without timezone has been deprecated in Pandas 1.2.0
# (see https://github.com/pandas-dev/pandas/pull/36148/) and is not support anymore in Pandas 2.0
# (see https://github.com/pandas-dev/pandas/pull/49492/).
# We explicitly remove the timezone from the start and stop of the slice to be able to use the
# index of the wrapped DataFrame.
start_wo_tz = item.start.replace(tzinfo=None) + timedelta(microseconds=1)
stop_wo_tz = item.stop.replace(tzinfo=None) - timedelta(microseconds=1)
open_ended = slice(start_wo_tz, stop_wo_tz, item.step)
return CustomTimeseries(
self.wrapped[open_ended],
with_timezone_attr=self.with_timezone_attr,
Expand Down

0 comments on commit 5b7c41c

Please sign in to comment.