fix(checker): correctly check length of frame/column
This commit is contained in:
@@ -355,6 +355,21 @@ class ColumnMethodRegistry(MethodRegistry[Call]):
|
|||||||
|
|
||||||
def _assert_same_length(self, call_expr: p.Expr, column1: p.Expr, column2: p.Expr):
|
def _assert_same_length(self, call_expr: p.Expr, column1: p.Expr, column2: p.Expr):
|
||||||
func_name: str = "__midas_column_same_length__"
|
func_name: str = "__midas_column_same_length__"
|
||||||
|
|
||||||
|
# Efficiently compute length
|
||||||
|
# https://stackoverflow.com/a/15943975/11109181
|
||||||
|
def len_of_col(col: ast.expr) -> ast.expr:
|
||||||
|
return ast.Call(
|
||||||
|
func=ast.Name(id="len"),
|
||||||
|
args=[
|
||||||
|
ast.Attribute(
|
||||||
|
value=col,
|
||||||
|
attr="index",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
keywords=[],
|
||||||
|
)
|
||||||
|
|
||||||
self.assertions.define(
|
self.assertions.define(
|
||||||
func_name,
|
func_name,
|
||||||
ast.FunctionDef(
|
ast.FunctionDef(
|
||||||
@@ -372,16 +387,10 @@ class ColumnMethodRegistry(MethodRegistry[Call]):
|
|||||||
body=[
|
body=[
|
||||||
ast.Return(
|
ast.Return(
|
||||||
value=ast.Compare(
|
value=ast.Compare(
|
||||||
left=ast.Attribute(
|
left=len_of_col(ast.Name(id="column1")),
|
||||||
value=ast.Name(id="column1"),
|
|
||||||
attr="size",
|
|
||||||
),
|
|
||||||
ops=[ast.Eq()],
|
ops=[ast.Eq()],
|
||||||
comparators=[
|
comparators=[
|
||||||
ast.Attribute(
|
len_of_col(ast.Name(id="column2")),
|
||||||
value=ast.Name(id="column2"),
|
|
||||||
attr="size",
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -434,6 +434,21 @@ class FrameMethodRegistry(MethodRegistry[Call]):
|
|||||||
|
|
||||||
def _assert_same_length(self, call_expr: p.Expr, frame1: p.Expr, frame2: p.Expr):
|
def _assert_same_length(self, call_expr: p.Expr, frame1: p.Expr, frame2: p.Expr):
|
||||||
func_name: str = "__midas_frame_same_length__"
|
func_name: str = "__midas_frame_same_length__"
|
||||||
|
|
||||||
|
# Efficiently compute length
|
||||||
|
# https://stackoverflow.com/a/15943975/11109181
|
||||||
|
def len_of_df(df: ast.expr) -> ast.expr:
|
||||||
|
return ast.Call(
|
||||||
|
func=ast.Name(id="len"),
|
||||||
|
args=[
|
||||||
|
ast.Attribute(
|
||||||
|
value=df,
|
||||||
|
attr="index",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
keywords=[],
|
||||||
|
)
|
||||||
|
|
||||||
self.assertions.define(
|
self.assertions.define(
|
||||||
func_name,
|
func_name,
|
||||||
ast.FunctionDef(
|
ast.FunctionDef(
|
||||||
@@ -451,17 +466,9 @@ class FrameMethodRegistry(MethodRegistry[Call]):
|
|||||||
body=[
|
body=[
|
||||||
ast.Return(
|
ast.Return(
|
||||||
value=ast.Compare(
|
value=ast.Compare(
|
||||||
left=ast.Attribute(
|
left=len_of_df(ast.Name(id="frame1")),
|
||||||
value=ast.Name(id="frame1"),
|
|
||||||
attr="size",
|
|
||||||
),
|
|
||||||
ops=[ast.Eq()],
|
ops=[ast.Eq()],
|
||||||
comparators=[
|
comparators=[len_of_df(ast.Name(id="frame2"))],
|
||||||
ast.Attribute(
|
|
||||||
value=ast.Name(id="frame2"),
|
|
||||||
attr="size",
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user