Compare commits
3
Commits
e855a09a6b
...
10c6ea7dda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10c6ea7dda
|
||
|
|
1acf33f376
|
||
|
|
aae481776f
|
@@ -5,7 +5,7 @@ type Celsius = float
|
|||||||
type Kelvin = float where _ >= 0
|
type Kelvin = float where _ >= 0
|
||||||
type Hectopascal = float
|
type Hectopascal = float
|
||||||
|
|
||||||
type Temperature = Celsius where in_range(-30.0, 100.0)
|
type Temperature = Celsius where in_range(-30.0, 100.0)(_)
|
||||||
type Pressure = Hectopascal where in_range(800.0, 1100.0)(_)
|
type Pressure = Hectopascal where in_range(800.0, 1100.0)(_)
|
||||||
type Humidity = float where is_percentage(_)
|
type Humidity = float where is_percentage(_)
|
||||||
type HeatIndex = float
|
type HeatIndex = float
|
||||||
@@ -61,5 +61,5 @@ alias DailyAverages = Frame[
|
|||||||
heat_index: Mean[HeatIndex],
|
heat_index: Mean[HeatIndex],
|
||||||
]
|
]
|
||||||
|
|
||||||
predicate limit_amplitude(max_amp: float)(ls: list[float]) = max(ls) - min(ls) <= max_amp
|
// predicate limit_amplitude(max_amp: float)(ls: list[float]) = max(ls) - min(ls) <= max_amp
|
||||||
type LowAmplitudeWave = list[float where _ >= 1] where limit_amplitude(10)(_)
|
// type LowAmplitudeWave = list[float where _ >= 1] where limit_amplitude(10)(_)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ delta = end_ts - start_ts
|
|||||||
|
|
||||||
min_temp, max_temp = -30.0, 100.0
|
min_temp, max_temp = -30.0, 100.0
|
||||||
min_pres, max_pres = 800.0, 1100.0
|
min_pres, max_pres = 800.0, 1100.0
|
||||||
min_hum, max_hum = 0.0, 1.0
|
min_hum, max_hum = 0.0, 100.0
|
||||||
|
|
||||||
N = 3000
|
N = 3000
|
||||||
|
|
||||||
|
|||||||
@@ -51,24 +51,25 @@ class FrameGroupByMethodRegistry(MethodRegistry[Call]):
|
|||||||
new_columns: list[DataFrameType.Column] = []
|
new_columns: list[DataFrameType.Column] = []
|
||||||
|
|
||||||
for column in call.groupby.frame.columns:
|
for column in call.groupby.frame.columns:
|
||||||
column_groupby: ColumnGroupBy = ColumnGroupBy(column=column.type)
|
with self.reporter.with_context(f"in column '{column.name}'"):
|
||||||
result_type: Type = self.typer.call_method(
|
column_groupby: ColumnGroupBy = ColumnGroupBy(column=column.type)
|
||||||
location=call.location,
|
result_type: Type = self.typer.call_method(
|
||||||
call_expr=call.call_expr,
|
location=call.location,
|
||||||
obj=(call.groupby_expr, column_groupby),
|
call_expr=call.call_expr,
|
||||||
method_name=method,
|
obj=(call.groupby_expr, column_groupby),
|
||||||
positional=call.positional,
|
method_name=method,
|
||||||
keywords=call.keywords,
|
positional=call.positional,
|
||||||
)
|
keywords=call.keywords,
|
||||||
if not isinstance(result_type, ColumnType):
|
)
|
||||||
result_type = ColumnType(type=UnknownType())
|
if not isinstance(result_type, ColumnType):
|
||||||
new_columns.append(
|
result_type = ColumnType(type=UnknownType())
|
||||||
DataFrameType.Column(
|
new_columns.append(
|
||||||
index=column.index,
|
DataFrameType.Column(
|
||||||
name=column.name,
|
index=column.index,
|
||||||
type=result_type,
|
name=column.name,
|
||||||
|
type=result_type,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return DataFrameType(columns=new_columns)
|
return DataFrameType(columns=new_columns)
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,10 @@ class FrameMethodRegistry(MethodRegistry[Call]):
|
|||||||
col_type2 = ColumnType(type=operand[1])
|
col_type2 = ColumnType(type=operand[1])
|
||||||
|
|
||||||
if col_type2 is not None:
|
if col_type2 is not None:
|
||||||
col_type = self._get_method_result(call, col_type1, col_type2, method)
|
with self.reporter.with_context(f"in column '{column.name}'"):
|
||||||
|
col_type = self._get_method_result(
|
||||||
|
call, col_type1, col_type2, method
|
||||||
|
)
|
||||||
|
|
||||||
new_column = DataFrameType.Column(
|
new_column = DataFrameType.Column(
|
||||||
index=column.index,
|
index=column.index,
|
||||||
|
|||||||
+11
-1
@@ -407,8 +407,18 @@ class MidasTyper(m.Stmt.Visitor[None], m.Expr.Visitor[Type], m.Type.Visitor[Type
|
|||||||
return UnknownType()
|
return UnknownType()
|
||||||
|
|
||||||
def visit_constraint_type(self, type: m.ConstraintType) -> Type:
|
def visit_constraint_type(self, type: m.ConstraintType) -> Type:
|
||||||
|
base_type: Type = type.type.accept(self)
|
||||||
|
self._predicate_params["_"] = base_type
|
||||||
|
constraint_type: Type = self.type_of(type.constraint)
|
||||||
|
self._predicate_params = {}
|
||||||
|
if not self.types.is_subtype(constraint_type, self._bool):
|
||||||
|
self.reporter.error(
|
||||||
|
type.location,
|
||||||
|
f"Constraint must evaluate to a boolean, got {constraint_type}",
|
||||||
|
)
|
||||||
|
|
||||||
return ConstraintType(
|
return ConstraintType(
|
||||||
type=type.type.accept(self),
|
type=base_type,
|
||||||
constraint=type.constraint,
|
constraint=type.constraint,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from midas.ast.location import Location
|
from midas.ast.location import Location
|
||||||
@@ -54,6 +55,7 @@ class FileReporter:
|
|||||||
def __init__(self, base_reporter: Reporter, path: Optional[str]) -> None:
|
def __init__(self, base_reporter: Reporter, path: Optional[str]) -> None:
|
||||||
self.base_reporter: Reporter = base_reporter
|
self.base_reporter: Reporter = base_reporter
|
||||||
self.path: Optional[str] = path
|
self.path: Optional[str] = path
|
||||||
|
self._context: list[str] = []
|
||||||
|
|
||||||
def for_file(self, path: Optional[str]) -> FileReporter:
|
def for_file(self, path: Optional[str]) -> FileReporter:
|
||||||
"""Create a new file reporter for the given path with the same base reporter
|
"""Create a new file reporter for the given path with the same base reporter
|
||||||
@@ -66,6 +68,14 @@ class FileReporter:
|
|||||||
"""
|
"""
|
||||||
return FileReporter(self.base_reporter, path)
|
return FileReporter(self.base_reporter, path)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def with_context(self, ctx: str):
|
||||||
|
self._context.append(ctx)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
self._context.pop()
|
||||||
|
|
||||||
def report(self, type: DiagnosticType, location: Location, message: str):
|
def report(self, type: DiagnosticType, location: Location, message: str):
|
||||||
"""Report a diagnostic to the base reporter
|
"""Report a diagnostic to the base reporter
|
||||||
|
|
||||||
@@ -74,6 +84,8 @@ class FileReporter:
|
|||||||
location (Location): the location of the diagnostic in the file
|
location (Location): the location of the diagnostic in the file
|
||||||
message (str): the diagnostic's message
|
message (str): the diagnostic's message
|
||||||
"""
|
"""
|
||||||
|
for ctx in self._context:
|
||||||
|
message = message + ", " + ctx
|
||||||
self.base_reporter.report(self.path, type, location, message)
|
self.base_reporter.report(self.path, type, location, message)
|
||||||
|
|
||||||
def error(self, location: Location, message: str):
|
def error(self, location: Location, message: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user