Skip to content

Commit

Permalink
Fixed dates in map_to_data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireDons committed Jun 10, 2024
1 parent 77984ac commit d1f8c3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lilio/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,15 @@ def _infer_time_bound(
left = input_data.index.min()
freq = xr.infer_freq(input_data.index)
if freq is not None:
time_delta = pd.Timedelta(freq)
right += time_delta / 2
left -= time_delta / 2
try:
time_delta = pd.to_timedelta(freq)
right += time_delta / 2
left -= time_delta / 2
except ValueError as exc:
if "w/o a number" in str(exc) or "only leading negative" in str(exc):
pass
else:
raise exc
return left, right

def map_to_data(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_map_to_data_edge_case_first_year(self):
# test the edge value when the input covers the anchor date
cal = daily_calendar(anchor="10-15", length="180d")
# multiple years covered
time_index = pd.date_range("20191010", "20211225", freq="60d")
time_index = pd.date_range("20190101", "20211225", freq="60d")
test_data = np.random.random(len(time_index))
timeseries = pd.Series(test_data, index=time_index)
cal.map_to_data(timeseries)
Expand All @@ -408,7 +408,7 @@ def test_map_to_data_edge_case_first_year(self):
def test_map_to_data_input_time_backward(self):
# test when the input data has reverse order time index
cal = daily_calendar(anchor="10-15", length="180d")
time_index = pd.date_range("20201010", "20211225", freq="60d")
time_index = pd.date_range("20200101", "20211225", freq="60d")
test_data = np.random.random(len(time_index))
timeseries = pd.Series(test_data, index=time_index[::-1])
cal.map_to_data(timeseries)
Expand All @@ -427,7 +427,7 @@ def test_map_to_data_input_time_backward(self):
def test_map_to_data_xarray_input(self):
# test when the input data has reverse order time index
cal = daily_calendar(anchor="10-15", length="180d")
time_index = pd.date_range("20201010", "20211225", freq="60d")
time_index = pd.date_range("20200101", "20211225", freq="60d")
test_data = np.random.random(len(time_index))
dataarray = xr.DataArray(data=test_data, coords={"time": time_index})
cal.map_to_data(dataarray)
Expand Down

0 comments on commit d1f8c3d

Please sign in to comment.