Skip to content

Commit

Permalink
minor edit and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Weidenholzer committed Aug 11, 2023
1 parent c8df82e commit aa0110b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 1 addition & 9 deletions openeo_processes_dask/process_implementations/cubes/_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@ def filter_temporal(
# The specified instance in time is excluded from the interval.
# See https://processes.openeo.org/#filter_temporal

try:
data = data.where(~np.isnat(data[applicable_temporal_dimension]), drop=True)
filtered = data.loc[
{applicable_temporal_dimension: slice(start_time, end_time)}
]
except:
try:
data = data.where(~np.isnat(data[applicable_temporal_dimension]), drop=True)
filtered = data.loc[
{applicable_temporal_dimension: slice(start_time, end_time)}
]
except Exception as e:
raise e

return filtered

Expand Down
7 changes: 7 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import copy
from functools import partial

import numpy as np
import pandas as pd
import pytest
import xarray as xr
from openeo_pg_parser_networkx.pg_schema import ParameterReference, TemporalInterval
Expand Down Expand Up @@ -59,6 +61,11 @@ def test_filter_temporal(temporal_interval, bounding_box, random_raster_data):
input_cube.loc[dict(t=slice("2018-05-01T00:00:00", "2018-05-02T23:59:59"))],
)

new_coords = list(copy.deepcopy(input_cube.coords["t"].data))
new_coords[1] = pd.NaT
invalid_input_cube = input_cube.assign_coords({"t": np.array(new_coords)})
filter_temporal(invalid_input_cube, temporal_interval)


@pytest.mark.parametrize("size", [(1, 1, 1, 2)])
@pytest.mark.parametrize("dtype", [np.uint8])
Expand Down

0 comments on commit aa0110b

Please sign in to comment.