From 83b7c63ad9233a9ed600f061d3b8e074291dcb8c Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Tue, 5 Apr 2022 19:57:13 +0200 Subject: [PATCH] Allowing intervals to actually contain subnodes --- pygeofilter/backends/native/evaluate.py | 12 ++++++++---- pygeofilter/values.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pygeofilter/backends/native/evaluate.py b/pygeofilter/backends/native/evaluate.py index 2d1c319..0913d6d 100644 --- a/pygeofilter/backends/native/evaluate.py +++ b/pygeofilter/backends/native/evaluate.py @@ -253,9 +253,8 @@ def literal(self, node): return key @handle(values.Interval) - def interval(self, node): - key = self._add_local(node) - return key + def interval(self, node, low, high): + return f'values.Interval({low}, {high})' @handle(values.Geometry) def geometry(self, node): @@ -281,8 +280,13 @@ def adopt_result(self, result): 'to_interval': to_interval, 'ensure_spatial': ensure_spatial, 'ast': ast, + 'values': values, } - assert set(globals_).isdisjoint(set(self.function_map)) + if not set(globals_).isdisjoint(set(self.function_map)): + raise ValueError( + f"globals collision {list(globals_)} and " + f"{list(self.function_map)}" + ) globals_.update(self.function_map) globals_.update(self.locals) diff --git a/pygeofilter/values.py b/pygeofilter/values.py index dfd812a..8b380a1 100644 --- a/pygeofilter/values.py +++ b/pygeofilter/values.py @@ -28,7 +28,7 @@ from dataclasses import dataclass from datetime import date, time, datetime, timedelta -from typing import Union, Optional +from typing import Any, List, Union, Optional from pygeoif.geometry import as_shape @@ -82,6 +82,9 @@ class Interval: start: Optional[Union[date, datetime, timedelta]] = None end: Optional[Union[date, datetime, timedelta]] = None + def get_sub_nodes(self) -> List[Any]: # TODO: find way to type this + return [self.start, self.end] + # used for handler declaration LITERALS = (list, str, float, int, bool, datetime, date, time, timedelta)