Skip to content

Commit

Permalink
Allowing intervals to actually contain subnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinius committed Apr 5, 2022
1 parent 80bc795 commit 83b7c63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pygeofilter/backends/native/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pygeofilter/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 83b7c63

Please sign in to comment.