Skip to content

Commit

Permalink
chore: fix warnings in test suite (#138)
Browse files Browse the repository at this point in the history
* filter unnecessary warning

* fix warning in test_apply

* suppress irrelevant deprecation warnings

* add comment
  • Loading branch information
LukeWeidenwalker authored Jul 14, 2023
1 parent aedbe70 commit f1582b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
24 changes: 15 additions & 9 deletions openeo_processes_dask/process_implementations/cubes/_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings
from typing import Callable

import numpy as np
Expand Down Expand Up @@ -46,15 +47,20 @@ def filter_temporal(
)
applicable_temporal_dimension = temporal_dims[0]

start_time = extent[0]
if start_time is not None:
start_time = start_time.to_numpy()
end_time = extent[1]
if end_time is not None:
end_time = extent[1].to_numpy() - np.timedelta64(1, "ms")
# The second element is the end of the temporal interval.
# The specified instance in time is excluded from the interval.
# See https://processes.openeo.org/#filter_temporal
# This line raises a deprecation warning, which according to this thread
# will never actually be deprecated:
# https://github.com/numpy/numpy/issues/23904
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
start_time = extent[0]
if start_time is not None:
start_time = start_time.to_numpy()
end_time = extent[1]
if end_time is not None:
end_time = extent[1].to_numpy() - np.timedelta64(1, "ms")
# The second element is the end of the temporal interval.
# The specified instance in time is excluded from the interval.
# See https://processes.openeo.org/#filter_temporal

filtered = data.loc[{applicable_temporal_dimension: slice(start_time, end_time)}]

Expand Down
17 changes: 12 additions & 5 deletions tests/mockdata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -34,11 +35,17 @@ def create_fake_rastercube(
max(spatial_extent.south, spatial_extent.north),
step=len_y / data.shape[1],
)
t_coords = pd.date_range(
start=np.datetime64(temporal_extent.__root__[0].__root__),
end=np.datetime64(temporal_extent.__root__[1].__root__),
periods=data.shape[2],
).values

# This line raises a deprecation warning, which according to this thread
# will never actually be deprecated:
# https://github.com/numpy/numpy/issues/23904
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
t_coords = pd.date_range(
start=np.datetime64(temporal_extent.__root__[0].__root__),
end=np.datetime64(temporal_extent.__root__[1].__root__),
periods=data.shape[2],
).values

coords = {"x": x_coords, "y": y_coords, "t": t_coords, "bands": bands}

Expand Down
5 changes: 2 additions & 3 deletions tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ def test_apply_dimension_target_dimension(
output_cube_reduced = apply_dimension(
data=input_cube, process=_process, dimension="x", target_dimension="y"
)

expected_output = (
(input_cube.mean(dim="x"))
input_cube.mean(dim="x")
.expand_dims("target")
.drop("y")
.drop_vars("y")
.rename({"target": "y"})
)

Expand Down

0 comments on commit f1582b3

Please sign in to comment.