Skip to content

Commit

Permalink
Fix reduction.Max not handling non-vals requests. (#93)
Browse files Browse the repository at this point in the history
* Fix reduction.Max not handlinge non-vals requests.

* Attempt to fix tests.

* Attempt to fix more tests.
  • Loading branch information
arjanverkerk committed Feb 8, 2022
1 parent cf83139 commit c1c090d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog of dask-geomodeling
2.3.7 (unreleased)
------------------

- Nothing changed yet.
- Fixed raster.Max not handling "time" and "meta" modes.


2.3.6 (2022-02-04)
Expand Down
12 changes: 10 additions & 2 deletions dask_geomodeling/raster/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,16 @@ def geometry(self):

def wrap_reduction_function(statistic):
def reduction_function(process_kwargs, *args):
# remove None values
stack = [x for x in args if x is not None]
stack = []
for arg in args:
if "time" in arg or "meta" in arg:
# return the time / meta right away. assumes there are no
# mixed requests and that time is aligned
return arg
if arg is None:
continue
stack.append(arg)

# return None if all source data is None
if len(stack) == 0:
return
Expand Down
8 changes: 6 additions & 2 deletions dask_geomodeling/tests/test_geometry_sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ def test_gml(self):
filename = [x for x in os.listdir(self.path) if x.endswith(".gml")][0]
actual = gpd.read_file(os.path.join(self.path, filename))

# GML writer adds an 'fid' column
del actual["fid"]
# GML writer adds an 'fid' column sometimes
for key in ("fid", "gml_id"):
try:
del actual[key]
except KeyError:
pass

# compare dataframes without checking the order of records / columns
assert_frame_equal_ignore_index(actual, self.expected, "int")
Expand Down
10 changes: 10 additions & 0 deletions dask_geomodeling/tests/test_raster_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,13 @@ def test_max_with_empty(source, empty_source, vals_request):
block = raster.Max(source, empty_source)
data = block.get_data(**vals_request)
assert data is None


def test_max_time_request(source):
block = raster.Max(source, source - 2)
time_request = {
"mode": "time",
"start": block.period[0],
}
data = block.get_data(**time_request)
assert data == {"time": [block.period[0]]}

0 comments on commit c1c090d

Please sign in to comment.