Compare commits
2
Commits
74472c974b
...
2b09a29165
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b09a29165
|
||
|
|
309e1d4a5b
|
@@ -0,0 +1,49 @@
|
|||||||
|
# type: ignore
|
||||||
|
# ruff: disable[F821]
|
||||||
|
|
||||||
|
import module1
|
||||||
|
import module2 as alias2
|
||||||
|
from module3 import submodule3
|
||||||
|
from module4 import submodule4 as alias4
|
||||||
|
|
||||||
|
a: int
|
||||||
|
b: Generic[int]
|
||||||
|
c: Generic2[int, float]
|
||||||
|
d: Frame[a:int, b:float]
|
||||||
|
|
||||||
|
e = 3
|
||||||
|
f: int = 4
|
||||||
|
g = []
|
||||||
|
h = [1, 0.1, " ", None, False, True]
|
||||||
|
i = {}
|
||||||
|
j = {"a": 1, "b": 2}
|
||||||
|
k = {"c": 3, **j}
|
||||||
|
l = cast(int, a)
|
||||||
|
m = unsafe_cast(int, a)
|
||||||
|
|
||||||
|
|
||||||
|
def n(a: int, /, b: float, *, c: str) -> Any:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def o(a: int = 1, /, b: float = 2.0, *, c: str = "") -> Any:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
for i in h:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if e == f:
|
||||||
|
pass
|
||||||
|
elif f == g:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
p = +a + -b - ~c * d / e**f
|
||||||
|
q = not (a and b) or c
|
||||||
|
r = a & b | c ^ d
|
||||||
|
|
||||||
|
s = a.b.c
|
||||||
|
t = a[b][c, d][e:f]
|
||||||
|
u = a(b)(c=d)
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
Module(
|
||||||
|
body=[
|
||||||
|
Import(
|
||||||
|
names=[
|
||||||
|
alias(name='module1')]),
|
||||||
|
Import(
|
||||||
|
names=[
|
||||||
|
alias(name='module2', asname='alias2')]),
|
||||||
|
ImportFrom(
|
||||||
|
module='module3',
|
||||||
|
names=[
|
||||||
|
alias(name='submodule3')],
|
||||||
|
level=0),
|
||||||
|
ImportFrom(
|
||||||
|
module='module4',
|
||||||
|
names=[
|
||||||
|
alias(name='submodule4', asname='alias4')],
|
||||||
|
level=0),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='e')],
|
||||||
|
value=Constant(value=3)),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='f')],
|
||||||
|
value=Constant(value=4)),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='g')],
|
||||||
|
value=List(elts=[])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='h')],
|
||||||
|
value=List(
|
||||||
|
elts=[
|
||||||
|
Constant(value=1),
|
||||||
|
Constant(value=0.1),
|
||||||
|
Constant(value=' '),
|
||||||
|
Constant(value=None),
|
||||||
|
Constant(value=False),
|
||||||
|
Constant(value=True)])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='i')],
|
||||||
|
value=Dict(keys=[], values=[])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='j')],
|
||||||
|
value=Dict(
|
||||||
|
keys=[
|
||||||
|
Constant(value='a'),
|
||||||
|
Constant(value='b')],
|
||||||
|
values=[
|
||||||
|
Constant(value=1),
|
||||||
|
Constant(value=2)])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='k')],
|
||||||
|
value=Dict(
|
||||||
|
keys=[
|
||||||
|
Constant(value='c'),
|
||||||
|
None],
|
||||||
|
values=[
|
||||||
|
Constant(value=3),
|
||||||
|
Name(id='j')])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
value=Name(id='a')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a0__'),
|
||||||
|
Name(id='int')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='03_simple_syntax.py:L21:5: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to int')])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='l')],
|
||||||
|
value=Name(id='__midas_a0__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a0__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='m')],
|
||||||
|
value=Name(id='a')),
|
||||||
|
FunctionDef(
|
||||||
|
name='n',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[
|
||||||
|
arg(arg='a')],
|
||||||
|
args=[
|
||||||
|
arg(arg='b')],
|
||||||
|
kwonlyargs=[
|
||||||
|
arg(arg='c')],
|
||||||
|
kw_defaults=[
|
||||||
|
None],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return()],
|
||||||
|
decorator_list=[]),
|
||||||
|
FunctionDef(
|
||||||
|
name='o',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[
|
||||||
|
arg(arg='a')],
|
||||||
|
args=[
|
||||||
|
arg(arg='b')],
|
||||||
|
kwonlyargs=[
|
||||||
|
arg(arg='c')],
|
||||||
|
kw_defaults=[
|
||||||
|
Constant(value='')],
|
||||||
|
defaults=[
|
||||||
|
Constant(value=1),
|
||||||
|
Constant(value=2.0)]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Constant(value=1))],
|
||||||
|
decorator_list=[]),
|
||||||
|
For(
|
||||||
|
target=Name(id='i'),
|
||||||
|
iter=Name(id='h'),
|
||||||
|
body=[
|
||||||
|
Pass()],
|
||||||
|
orelse=[]),
|
||||||
|
If(
|
||||||
|
test=Compare(
|
||||||
|
left=Name(id='e'),
|
||||||
|
ops=[
|
||||||
|
Eq()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='f')]),
|
||||||
|
body=[
|
||||||
|
Pass()],
|
||||||
|
orelse=[
|
||||||
|
If(
|
||||||
|
test=Compare(
|
||||||
|
left=Name(id='f'),
|
||||||
|
ops=[
|
||||||
|
Eq()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='g')]),
|
||||||
|
body=[
|
||||||
|
Pass()],
|
||||||
|
orelse=[])]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='p')],
|
||||||
|
value=BinOp(
|
||||||
|
left=BinOp(
|
||||||
|
left=UnaryOp(
|
||||||
|
op=UAdd(),
|
||||||
|
operand=Name(id='a')),
|
||||||
|
op=Add(),
|
||||||
|
right=UnaryOp(
|
||||||
|
op=USub(),
|
||||||
|
operand=Name(id='b'))),
|
||||||
|
op=Sub(),
|
||||||
|
right=BinOp(
|
||||||
|
left=BinOp(
|
||||||
|
left=UnaryOp(
|
||||||
|
op=Invert(),
|
||||||
|
operand=Name(id='c')),
|
||||||
|
op=Mult(),
|
||||||
|
right=Name(id='d')),
|
||||||
|
op=Div(),
|
||||||
|
right=BinOp(
|
||||||
|
left=Name(id='e'),
|
||||||
|
op=Pow(),
|
||||||
|
right=Name(id='f'))))),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='q')],
|
||||||
|
value=BoolOp(
|
||||||
|
op=Or(),
|
||||||
|
values=[
|
||||||
|
UnaryOp(
|
||||||
|
op=Not(),
|
||||||
|
operand=BoolOp(
|
||||||
|
op=And(),
|
||||||
|
values=[
|
||||||
|
Name(id='a'),
|
||||||
|
Name(id='b')])),
|
||||||
|
Name(id='c')])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='r')],
|
||||||
|
value=BinOp(
|
||||||
|
left=BinOp(
|
||||||
|
left=Name(id='a'),
|
||||||
|
op=BitAnd(),
|
||||||
|
right=Name(id='b')),
|
||||||
|
op=BitOr(),
|
||||||
|
right=BinOp(
|
||||||
|
left=Name(id='c'),
|
||||||
|
op=BitXor(),
|
||||||
|
right=Name(id='d')))),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='s')],
|
||||||
|
value=Attribute(
|
||||||
|
value=Attribute(
|
||||||
|
value=Name(id='a'),
|
||||||
|
attr='b'),
|
||||||
|
attr='c')),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='t')],
|
||||||
|
value=Subscript(
|
||||||
|
value=Subscript(
|
||||||
|
value=Subscript(
|
||||||
|
value=Name(id='a'),
|
||||||
|
slice=Name(id='b')),
|
||||||
|
slice=Tuple(
|
||||||
|
elts=[
|
||||||
|
Name(id='c'),
|
||||||
|
Name(id='d')])),
|
||||||
|
slice=Slice(
|
||||||
|
lower=Name(id='e'),
|
||||||
|
upper=Name(id='f')))),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='u')],
|
||||||
|
value=Call(
|
||||||
|
func=Call(
|
||||||
|
func=Name(id='a'),
|
||||||
|
args=[
|
||||||
|
Name(id='b')],
|
||||||
|
keywords=[]),
|
||||||
|
args=[],
|
||||||
|
keywords=[
|
||||||
|
keyword(
|
||||||
|
arg='c',
|
||||||
|
value=Name(id='d'))]))],
|
||||||
|
type_ignores=[])
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
predicate is_positive(v: float) = v >= 0
|
||||||
|
type Positive = float where is_positive(_)
|
||||||
|
|
||||||
|
alias T1 = Frame[
|
||||||
|
a: int
|
||||||
|
]
|
||||||
|
|
||||||
|
alias T2 = Frame[
|
||||||
|
a: int,
|
||||||
|
b: str,
|
||||||
|
c: Positive,
|
||||||
|
d: float where is_positive(_)
|
||||||
|
]
|
||||||
|
|
||||||
|
alias Positives = Column[Positive]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from midas import T1, T2, Column, Positive, Positives, cast
|
||||||
|
|
||||||
|
o: Any = object()
|
||||||
|
|
||||||
|
df1 = cast(T1, o)
|
||||||
|
df2 = cast(T2, o)
|
||||||
|
|
||||||
|
df1 + df2
|
||||||
|
|
||||||
|
col1: Positives = df2["c"]
|
||||||
|
col2 = cast(Column[Positive], col1)
|
||||||
@@ -0,0 +1,731 @@
|
|||||||
|
Module(
|
||||||
|
body=[
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_column_same_length__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[],
|
||||||
|
args=[
|
||||||
|
arg(arg='column1'),
|
||||||
|
arg(arg='column2')],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Compare(
|
||||||
|
left=Call(
|
||||||
|
func=Name(id='len'),
|
||||||
|
args=[
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='column1'),
|
||||||
|
attr='index')],
|
||||||
|
keywords=[]),
|
||||||
|
ops=[
|
||||||
|
Eq()],
|
||||||
|
comparators=[
|
||||||
|
Call(
|
||||||
|
func=Name(id='len'),
|
||||||
|
args=[
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='column2'),
|
||||||
|
attr='index')],
|
||||||
|
keywords=[])]))],
|
||||||
|
decorator_list=[]),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_frame_same_length__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[],
|
||||||
|
args=[
|
||||||
|
arg(arg='frame1'),
|
||||||
|
arg(arg='frame2')],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Compare(
|
||||||
|
left=Call(
|
||||||
|
func=Name(id='len'),
|
||||||
|
args=[
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='frame1'),
|
||||||
|
attr='index')],
|
||||||
|
keywords=[]),
|
||||||
|
ops=[
|
||||||
|
Eq()],
|
||||||
|
comparators=[
|
||||||
|
Call(
|
||||||
|
func=Name(id='len'),
|
||||||
|
args=[
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='frame2'),
|
||||||
|
attr='index')],
|
||||||
|
keywords=[])]))],
|
||||||
|
decorator_list=[]),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_is_column__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[
|
||||||
|
arg(arg='obj')],
|
||||||
|
args=[],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Import(
|
||||||
|
names=[
|
||||||
|
alias(name='pandas', asname='pd')]),
|
||||||
|
Return(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='obj'),
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='pd'),
|
||||||
|
attr='Series')],
|
||||||
|
keywords=[]))],
|
||||||
|
decorator_list=[],
|
||||||
|
returns=Name(id='bool')),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_is_dataframe__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[
|
||||||
|
arg(arg='obj')],
|
||||||
|
args=[],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Import(
|
||||||
|
names=[
|
||||||
|
alias(name='pandas', asname='pd')]),
|
||||||
|
Return(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='obj'),
|
||||||
|
Attribute(
|
||||||
|
value=Name(id='pd'),
|
||||||
|
attr='DataFrame')],
|
||||||
|
keywords=[]))],
|
||||||
|
decorator_list=[],
|
||||||
|
returns=Name(id='bool')),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_is_positive__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[],
|
||||||
|
args=[
|
||||||
|
arg(
|
||||||
|
arg='v',
|
||||||
|
annotation=Constant(value='float'))],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Compare(
|
||||||
|
left=Name(id='v'),
|
||||||
|
ops=[
|
||||||
|
GtE()],
|
||||||
|
comparators=[
|
||||||
|
Constant(value=0)]))],
|
||||||
|
decorator_list=[],
|
||||||
|
returns=Constant(value='bool')),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_p0__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[],
|
||||||
|
args=[
|
||||||
|
arg(
|
||||||
|
arg='_',
|
||||||
|
annotation=Constant(value='Any'))],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='__midas_is_positive__'),
|
||||||
|
args=[
|
||||||
|
Name(id='_')],
|
||||||
|
keywords=[]))],
|
||||||
|
decorator_list=[],
|
||||||
|
returns=Constant(value='bool')),
|
||||||
|
FunctionDef(
|
||||||
|
name='__midas_p1__',
|
||||||
|
args=arguments(
|
||||||
|
posonlyargs=[],
|
||||||
|
args=[
|
||||||
|
arg(
|
||||||
|
arg='_',
|
||||||
|
annotation=Constant(value='Any'))],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[],
|
||||||
|
defaults=[]),
|
||||||
|
body=[
|
||||||
|
Return(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='__midas_is_positive__'),
|
||||||
|
args=[
|
||||||
|
Name(id='_')],
|
||||||
|
keywords=[]))],
|
||||||
|
decorator_list=[],
|
||||||
|
returns=Constant(value='bool')),
|
||||||
|
ImportFrom(
|
||||||
|
module='typing',
|
||||||
|
names=[
|
||||||
|
alias(name='Any')],
|
||||||
|
level=0),
|
||||||
|
ImportFrom(
|
||||||
|
module='midas',
|
||||||
|
names=[
|
||||||
|
alias(name='T1'),
|
||||||
|
alias(name='T2'),
|
||||||
|
alias(name='Column'),
|
||||||
|
alias(name='Positive'),
|
||||||
|
alias(name='Positives'),
|
||||||
|
alias(name='cast')],
|
||||||
|
level=0),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='o')],
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='object'),
|
||||||
|
args=[],
|
||||||
|
keywords=[])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
value=Name(id='o')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_dataframe__'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L7:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to Frame[a: Column[int]]: Not a dataframe')])),
|
||||||
|
Assert(
|
||||||
|
test=Compare(
|
||||||
|
left=Constant(value='a'),
|
||||||
|
ops=[
|
||||||
|
In()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='__midas_a0__')]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L7:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a0__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Frame[a: Column[int]]: Missing column 'a'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a0__'),
|
||||||
|
slice=Constant(value='a'))],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L7:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a0__'),
|
||||||
|
slice=Constant(value='a'))],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Column[int], in column 'a': Not a column")])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Subscript(
|
||||||
|
value=Name(id='__midas_a0__'),
|
||||||
|
slice=Constant(value='a')),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='int')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L7:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to int, in column 'a'")]))],
|
||||||
|
orelse=[]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='df1')],
|
||||||
|
value=Name(id='__midas_a0__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a0__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
value=Name(id='o')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_dataframe__'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to Frame[a: Column[int], b: Column[str], c: Column[Positive], d: Column[float where is_positive(_)]]: Not a dataframe')])),
|
||||||
|
Assert(
|
||||||
|
test=Compare(
|
||||||
|
left=Constant(value='a'),
|
||||||
|
ops=[
|
||||||
|
In()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='__midas_a1__')]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Frame[a: Column[int], b: Column[str], c: Column[Positive], d: Column[float where is_positive(_)]]: Missing column 'a'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='a'))],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='a'))],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Column[int], in column 'a': Not a column")])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='a')),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='int')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to int, in column 'a'")]))],
|
||||||
|
orelse=[]),
|
||||||
|
Assert(
|
||||||
|
test=Compare(
|
||||||
|
left=Constant(value='b'),
|
||||||
|
ops=[
|
||||||
|
In()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='__midas_a1__')]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Frame[a: Column[int], b: Column[str], c: Column[Positive], d: Column[float where is_positive(_)]]: Missing column 'b'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='b'))],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='b'))],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Column[str], in column 'b': Not a column")])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='b')),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='str')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to str, in column 'b'")]))],
|
||||||
|
orelse=[]),
|
||||||
|
Assert(
|
||||||
|
test=Compare(
|
||||||
|
left=Constant(value='c'),
|
||||||
|
ops=[
|
||||||
|
In()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='__midas_a1__')]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Frame[a: Column[int], b: Column[str], c: Column[Positive], d: Column[float where is_positive(_)]]: Missing column 'c'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='c'))],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='c'))],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Column[Positive], in column 'c': Not a column")])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='c')),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='float')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to float, in column 'c'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_p0__'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=Constant(value="04_frames.py:L8:7: ConstraintError: Value does not fit constraint 'is_positive(_)', in column 'c'"))],
|
||||||
|
orelse=[]),
|
||||||
|
Assert(
|
||||||
|
test=Compare(
|
||||||
|
left=Constant(value='d'),
|
||||||
|
ops=[
|
||||||
|
In()],
|
||||||
|
comparators=[
|
||||||
|
Name(id='__midas_a1__')]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Frame[a: Column[int], b: Column[str], c: Column[Positive], d: Column[float where is_positive(_)]]: Missing column 'd'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='d'))],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='d'))],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to Column[float where is_positive(_)], in column 'd': Not a column")])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Subscript(
|
||||||
|
value=Name(id='__midas_a1__'),
|
||||||
|
slice=Constant(value='d')),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='float')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L8:7: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=" to float, in column 'd'")])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_p1__'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=Constant(value="04_frames.py:L8:7: ConstraintError: Value does not fit constraint 'is_positive(_)', in column 'd'"))],
|
||||||
|
orelse=[]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='df2')],
|
||||||
|
value=Name(id='__midas_a1__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a1__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a2__')],
|
||||||
|
value=Name(id='df1')),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a3__')],
|
||||||
|
value=Name(id='df2')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_column_same_length__'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a2__'),
|
||||||
|
Name(id='__midas_a3__')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=Constant(value='04_frames.py:L10:1: AssertionError: Columns must have the same length')),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a4__')],
|
||||||
|
value=Name(id='__midas_a2__')),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a5__')],
|
||||||
|
value=Name(id='__midas_a3__')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_frame_same_length__'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a4__'),
|
||||||
|
Name(id='__midas_a5__')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=Constant(value='04_frames.py:L10:1: AssertionError: DataFrames must have the same length')),
|
||||||
|
Expr(
|
||||||
|
value=BinOp(
|
||||||
|
left=Name(id='__midas_a2__'),
|
||||||
|
op=Add(),
|
||||||
|
right=Name(id='__midas_a3__'))),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a2__'),
|
||||||
|
Name(id='__midas_a3__'),
|
||||||
|
Name(id='__midas_a4__'),
|
||||||
|
Name(id='__midas_a5__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='col1')],
|
||||||
|
value=Subscript(
|
||||||
|
value=Name(id='df2'),
|
||||||
|
slice=Constant(value='c'))),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a6__')],
|
||||||
|
value=Name(id='col1')),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_is_column__'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a6__')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L13:8: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_a6__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to Column[Positive]: Not a column')])),
|
||||||
|
For(
|
||||||
|
target=Name(id='value'),
|
||||||
|
iter=Name(id='__midas_a6__'),
|
||||||
|
body=[
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='value'),
|
||||||
|
Name(id='float')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='04_frames.py:L13:8: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to float')])),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='__midas_p0__'),
|
||||||
|
args=[
|
||||||
|
Name(id='value')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=Constant(value="04_frames.py:L13:8: ConstraintError: Value does not fit constraint 'is_positive(_)'"))],
|
||||||
|
orelse=[]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='col2')],
|
||||||
|
value=Name(id='__midas_a6__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_a6__')])],
|
||||||
|
type_ignores=[])
|
||||||
+5
-5
@@ -3,7 +3,6 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from midas.checker.checker import TypeChecker
|
from midas.checker.checker import TypeChecker
|
||||||
from midas.checker.diagnostic import DiagnosticType
|
|
||||||
from midas.generator.generator import Generator
|
from midas.generator.generator import Generator
|
||||||
from midas.utils import TypedAST
|
from midas.utils import TypedAST
|
||||||
from tests.base import Tester
|
from tests.base import Tester
|
||||||
@@ -44,10 +43,11 @@ class GeneratorTester(Tester):
|
|||||||
|
|
||||||
typed_ast: TypedAST = checker.type_check(path)
|
typed_ast: TypedAST = checker.type_check(path)
|
||||||
|
|
||||||
if not any(d.type == DiagnosticType.ERROR for d in checker.diagnostics):
|
# Ignore errors and generate anyway, easier here and errors should be
|
||||||
generator = Generator(workdir=path.parent, types=checker.types)
|
# covered by checker tests
|
||||||
generator.set_src_path(path)
|
generator = Generator(workdir=path.parent, types=checker.types)
|
||||||
result.compiled_ast = generator.generate_ast(typed_ast)
|
generator.set_src_path(path)
|
||||||
|
result.compiled_ast = generator.generate_ast(typed_ast)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user