Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwutk committed Aug 7, 2023
1 parent ef75963 commit 4d8e775
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 220 deletions.
2 changes: 0 additions & 2 deletions spatialyze/data_types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .bounding_box import BoundingBox
from .box import Box
from .camera import Camera
from .camera_config import CameraConfig
Expand All @@ -7,7 +6,6 @@
from .trajectory import Trajectory

__all__ = [
"BoundingBox",
"Box",
"CameraConfig",
"Camera",
Expand Down
34 changes: 0 additions & 34 deletions spatialyze/data_types/bounding_box.py

This file was deleted.

9 changes: 4 additions & 5 deletions spatialyze/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import environ
from typing import TYPE_CHECKING, Callable, List, Tuple
from typing import TYPE_CHECKING, Callable

import pandas as pd
import psycopg2
Expand All @@ -9,7 +9,6 @@
# from mobilitydb.psycopg import register as mobilitydb_register
from postgis.psycopg import register as postgis_register

from spatialyze.data_types import Trajectory
from spatialyze.predicate import (
FindAllTablesVisitor,
GenSqlVisitor,
Expand Down Expand Up @@ -69,15 +68,15 @@
]


def columns(fn: Callable[[Tuple[str, str]], str], columns: List[Tuple[str, str]]) -> str:
def columns(fn: "Callable[[tuple[str, str]], str]", columns: "list[tuple[str, str]]") -> str:
return ",".join(map(fn, columns))


def _schema(column: Tuple[str, str]) -> str:
def _schema(column: "tuple[str, str]") -> str:
return " ".join(column)


def _name(column: Tuple[str, str]) -> str:
def _name(column: "tuple[str, str]") -> str:
return column[0]


Expand Down
47 changes: 21 additions & 26 deletions spatialyze/predicate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from typing import (
Any,
Callable,
Dict,
Generic,
List,
Literal,
Optional,
Set,
Tuple,
TypeVar,
)

Expand Down Expand Up @@ -132,7 +127,7 @@ def __repr__(self):


class ArrayNode(PredicateNode):
exprs: List["PredicateNode"]
exprs: "list[PredicateNode]"


def wrap_literal(x: Any) -> "PredicateNode":
Expand Down Expand Up @@ -161,7 +156,7 @@ class BinOpNode(PredicateNode):

class BoolOpNode(PredicateNode):
op: BoolOp
exprs: List["PredicateNode"]
exprs: "list[PredicateNode]"


class UnaryOpNode(PredicateNode):
Expand All @@ -179,7 +174,7 @@ def lit(value: Any, python: bool = True):


class TableNode(PredicateNode):
index: Optional[int]
index: "int | None"

def __getattr__(self, name: str) -> "TableAttrNode":
return TableAttrNode(name, self, False)
Expand All @@ -202,7 +197,7 @@ def __init__(self, index: int):


class CameraTableNode(TableNode):
def __init__(self, index: Optional[int] = None):
def __init__(self, index: "int | None" = None):
self.index = index
self.time = TableAttrNode("timestamp", self, True)
self.ego = TableAttrNode("egoTranslation", self, True)
Expand Down Expand Up @@ -230,12 +225,12 @@ def __getitem__(self, index: int) -> "CameraTableNode":
camera = CameraTableNode()


Fn = Callable[["GenSqlVisitor", List["PredicateNode"]], str]
Fn = Callable[["GenSqlVisitor", "list[PredicateNode]"], str]


class CallNode(PredicateNode):
_fn: Tuple["Fn"]
params: List["PredicateNode"]
_fn: "tuple[Fn]"
params: "list[PredicateNode]"

def __init__(self, fn: "Fn", name: "str", params: "list[PredicateNode]"):
self._fn = (fn,)
Expand Down Expand Up @@ -358,7 +353,7 @@ def visit_CastNode(self, node: "CastNode"):
class ExpandBoolOpTransformer(BaseTransformer):
def __call__(self, node: "PredicateNode"):
if isinstance(node, BoolOpNode):
exprs: List["PredicateNode"] = []
exprs: "list[PredicateNode]" = []
for expr in node.exprs:
e = self(expr)
if isinstance(e, BoolOpNode) and e.op == node.op:
Expand All @@ -369,8 +364,8 @@ def __call__(self, node: "PredicateNode"):
return super().__call__(node)


class FindAllTablesVisitor(Visitor[Tuple[Set[int], bool]]):
tables: Set[int]
class FindAllTablesVisitor(Visitor["tuple[set[int], bool]"]):
tables: "set[int]"
camera: bool

def __init__(self):
Expand All @@ -393,9 +388,9 @@ def reset(self):


class MapTablesTransformer(BaseTransformer):
mapping: Dict[int, int]
mapping: "dict[int, int]"

def __init__(self, mapping: Dict[int, int]):
def __init__(self, mapping: "dict[int, int]"):
self.mapping = mapping

def visit_ObjectTableNode(self, node: "ObjectTableNode"):
Expand All @@ -415,7 +410,7 @@ def visit_BinOpNode(self, node: "BinOpNode"):
return node


normalizers: List[BaseTransformer] = [ExpandBoolOpTransformer(), NormalizeArrayAtTime()]
normalizers: "list[BaseTransformer]" = [ExpandBoolOpTransformer(), NormalizeArrayAtTime()]


def normalize(predicate: "PredicateNode") -> "PredicateNode":
Expand All @@ -425,19 +420,19 @@ def normalize(predicate: "PredicateNode") -> "PredicateNode":
return predicate


BIN_OP: Dict[BinOp, str] = {
BIN_OP: "dict[BinOp, str]" = {
"add": "+",
"sub": "-",
"mul": "*",
"div": "/",
}

BOOL_OP: Dict[BoolOp, str] = {
BOOL_OP: "dict[BoolOp, str]" = {
"and": " AND ",
"or": " OR ",
}

COMP_OP: Dict[CompOp, str] = {
COMP_OP: "dict[CompOp, str]" = {
"eq": "=",
"ne": "<>",
"ge": ">=",
Expand All @@ -446,7 +441,7 @@ def normalize(predicate: "PredicateNode") -> "PredicateNode":
"lt": "<",
}

UNARY_OP: Dict[UnaryOp, str] = {
UNARY_OP: "dict[UnaryOp, str]" = {
"invert": "NOT ",
"neg": "-",
}
Expand Down Expand Up @@ -514,20 +509,20 @@ def visit_CastNode(self, node: "CastNode"):
return f"({self(node.expr)})::{node.to}"


def resolve_object_attr(attr: str, num: Optional[int] = None):
def resolve_object_attr(attr: str, num: "int | None" = None):
if num is None:
return attr
return f"t{num}.{attr}"


def resolve_camera_attr(attr: str, num: Optional[int] = None):
def resolve_camera_attr(attr: str, num: "int | None" = None):
if num is None:
return attr
return f"c{num}.{attr}"


# TODO: this is duplicate with the one in database.py
TRAJECTORY_COLUMNS: List[Tuple[str, str]] = [
TRAJECTORY_COLUMNS: "list[tuple[str, str]]" = [
("itemId", "TEXT"),
("cameraId", "TEXT"),
("objectType", "TEXT"),
Expand All @@ -538,7 +533,7 @@ def resolve_camera_attr(attr: str, num: Optional[int] = None):
]


CAMERA_COLUMNS: List[Tuple[str, str]] = [
CAMERA_COLUMNS: "list[tuple[str, str]]" = [
("cameraId", "TEXT"),
("frameId", "TEXT"),
("frameNum", "Int"),
Expand Down
4 changes: 1 addition & 3 deletions spatialyze/utils/F/ahead.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from spatialyze.predicate import (
BinOpNode,
GenSqlVisitor,
Expand All @@ -12,7 +10,7 @@


@call_node
def ahead(visitor: "GenSqlVisitor", args: "List[PredicateNode]"):
def ahead(visitor: "GenSqlVisitor", args: "list[PredicateNode]"):
obj1, obj2 = args

if not isinstance(obj2, TableAttrNode) and (
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions spatialyze/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def addGeogConstructs(self, geogConstructs: "RoadNetwork"):

def object(self, index: "int | None" = None):
if index is not None:
node = ObjectTableNode(self._objectCounts)
self._objectCounts += 1
else:
node = ObjectTableNode(index)
return ObjectTableNode(index)

Check warning on line 34 in spatialyze/world.py

View check run for this annotation

Codecov / codecov/patch

spatialyze/world.py#L32-L34

Added lines #L32 - L34 were not covered by tests

node = ObjectTableNode(self._objectCounts)
self._objectCounts += 1
return node

Check warning on line 38 in spatialyze/world.py

View check run for this annotation

Codecov / codecov/patch

spatialyze/world.py#L36-L38

Added lines #L36 - L38 were not covered by tests

def camera(self):
Expand Down

0 comments on commit 4d8e775

Please sign in to comment.