Skip to content
14 changes: 10 additions & 4 deletions python/datafusion/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

__all__ = [
"Expr",
"RawExpr",

Check failure on line 105 in python/datafusion/expr.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F822)

python/datafusion/expr.py:105:5: F822 Undefined name `RawExpr` in `__all__`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing this caused the test to fail. I'll add this again and run the tests locally again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its removal is causing the tests to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a line in the test:

if isinstance(internal_attr, list):
            assert isinstance(wrapped_attr, list)
            for val in internal_attr:
                if isinstance(val, str) and val.startswith("Raw"): #<---- added this line since we check for all Raw* classes in the previous part of the code
                    continue
                assert val in wrapped_attr

"Column",
"Literal",
"BinaryExpr",
Expand Down Expand Up @@ -193,10 +194,15 @@
:ref:`Expressions` in the online documentation for more information.
"""

def __init__(self, expr: expr_internal.Expr) -> None:
def __init__(self, expr: expr_internal.RawExpr) -> None:
"""This constructor should not be called by the end user."""
self.expr = expr

@property

Check failure on line 201 in python/datafusion/expr.py

View workflow job for this annotation

GitHub Actions / build

Ruff (W291)

python/datafusion/expr.py:201:14: W291 Trailing whitespace
def raw_expr(self) -> expr_internal.RawExpr:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this.

"""Returns the underlying RawExpr instance."""
return self.expr

def to_variant(self) -> Any:
"""Convert this expression into a python object if possible."""
return self.expr.to_variant()
Expand Down Expand Up @@ -383,7 +389,7 @@
value = pa.scalar(value, type=pa.string_view())
if not isinstance(value, pa.Scalar):
value = pa.scalar(value)
return Expr(expr_internal.Expr.literal(value))
return Expr(expr_internal.RawExpr.literal(value))

@staticmethod
def string_literal(value: str) -> Expr:
Expand All @@ -398,13 +404,13 @@
"""
if isinstance(value, str):
value = pa.scalar(value, type=pa.string())
return Expr(expr_internal.Expr.literal(value))
return Expr(expr_internal.RawExpr.literal(value))
return Expr.literal(value)

@staticmethod
def column(value: str) -> Expr:
"""Creates a new expression representing a column."""
return Expr(expr_internal.Expr.column(value))
return Expr(expr_internal.RawExpr.column(value))

def alias(self, name: str) -> Expr:
"""Assign a name to the expression."""
Expand Down
7 changes: 6 additions & 1 deletion python/tests/test_wrapper_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
for attr in dir(internal_obj):
if attr in ["_global_ctx"]:
continue
assert attr in dir(wrapped_obj)

Check failure on line 39 in python/tests/test_wrapper_coverage.py

View workflow job for this annotation

GitHub Actions / build

Ruff (W293)

python/tests/test_wrapper_coverage.py:39:1: W293 Blank line contains whitespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you apply ruff it should correct these whitespace errors. I recommend turning on pre-commit in your local workspace to catch them before they get to CI.

# Check if Raw* classes have corresponding wrapper classes
if attr.startswith("Raw"):
base_class = attr[3:] # Remove "Raw" prefix
assert hasattr(wrapped_obj, base_class), f"Missing implementation for {attr}"
continue

internal_attr = getattr(internal_obj, attr)
wrapped_attr = getattr(wrapped_obj, attr)
Expand Down
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod window;
use sort_expr::{to_sort_expressions, PySortExpr};

/// A PyExpr that can be used on a DataFrame
#[pyclass(name = "Expr", module = "datafusion.expr", subclass)]
#[pyclass(name = "RawExpr", module = "datafusion.expr", subclass)]
#[derive(Debug, Clone)]
pub struct PyExpr {
pub expr: Expr,
Expand Down
Loading