diff --git a/python/datafusion/expr.py b/python/datafusion/expr.py index 71fcf397..84bb7022 100644 --- a/python/datafusion/expr.py +++ b/python/datafusion/expr.py @@ -175,7 +175,16 @@ def display_name(self) -> str: This name will not include any CAST expressions. """ - return self.expr.display_name() + import warnings + warnings.warn("deprecated since 40.0.0: use schema_name instead", DeprecationWarning) + return self.schema_name() + + def schema_name(self) -> str: + """Returns the name of this expression as it should appear in a schema. + + This name will not include any CAST expressions. + """ + return self.expr.schema_name() def canonical_name(self) -> str: """Returns a complete string representation of this expression.""" diff --git a/python/datafusion/tests/test_expr.py b/python/datafusion/tests/test_expr.py index 1a41120a..1dd3d230 100644 --- a/python/datafusion/tests/test_expr.py +++ b/python/datafusion/tests/test_expr.py @@ -167,3 +167,23 @@ def traverse_logical_plan(plan): assert variant.expr().to_variant().qualified_name() == 'table1.name' assert str(variant.list()) == '[Expr(Utf8("dfa")), Expr(Utf8("ad")), Expr(Utf8("dfre")), Expr(Utf8("vsa"))]' assert not variant.negated() + + +def test_display_name_deprecation(): + import warnings + expr = col("foo") + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered + warnings.simplefilter("always") + + # should trigger warning + name = expr.display_name() + + # Verify some things + assert len(w) == 1 + assert issubclass(w[-1].category, DeprecationWarning) + assert "deprecated" in str(w[-1].message) + + # returns appropriate result + assert name == expr.schema_name() + assert name == "foo" diff --git a/src/expr.rs b/src/expr.rs index 04bfc85c..487db482 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -187,8 +187,8 @@ impl PyExpr { /// Returns the name of this expression as it should appear in a schema. This name /// will not include any CAST expressions. - fn display_name(&self) -> PyResult { - Ok(self.expr.display_name()?) + fn schema_name(&self) -> PyResult { + Ok(format!("{}", self.expr.schema_name())) } /// Returns a full and complete string representation of this expression.