Skip to content

Commit a09d848

Browse files
deprecate Expr::display_name
Ref: apache/datafusion#11797
1 parent 14f18ad commit a09d848

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

python/datafusion/expr.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,16 @@ def display_name(self) -> str:
175175
176176
This name will not include any CAST expressions.
177177
"""
178-
return self.expr.display_name()
178+
import warnings
179+
warnings.warn("deprecated since 40.0.0: use schema_name instead", DeprecationWarning)
180+
return self.schema_name()
181+
182+
def schema_name(self) -> str:
183+
"""Returns the name of this expression as it should appear in a schema.
184+
185+
This name will not include any CAST expressions.
186+
"""
187+
return self.expr.schema_name()
179188

180189
def canonical_name(self) -> str:
181190
"""Returns a complete string representation of this expression."""

python/datafusion/tests/test_expr.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,23 @@ def traverse_logical_plan(plan):
167167
assert variant.expr().to_variant().qualified_name() == 'table1.name'
168168
assert str(variant.list()) == '[Expr(Utf8("dfa")), Expr(Utf8("ad")), Expr(Utf8("dfre")), Expr(Utf8("vsa"))]'
169169
assert not variant.negated()
170+
171+
172+
def test_display_name_deprecation():
173+
import warnings
174+
expr = col("foo")
175+
with warnings.catch_warnings(record=True) as w:
176+
# Cause all warnings to always be triggered
177+
warnings.simplefilter("always")
178+
179+
# should trigger warning
180+
name = expr.display_name()
181+
182+
# Verify some things
183+
assert len(w) == 1
184+
assert issubclass(w[-1].category, DeprecationWarning)
185+
assert "deprecated" in str(w[-1].message)
186+
187+
# returns appropriate result
188+
assert name == expr.schema_name()
189+
assert name == "foo"

src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ impl PyExpr {
187187

188188
/// Returns the name of this expression as it should appear in a schema. This name
189189
/// will not include any CAST expressions.
190-
fn display_name(&self) -> PyResult<String> {
191-
Ok(self.expr.display_name()?)
190+
fn schema_name(&self) -> PyResult<String> {
191+
Ok(format!("{}", self.expr.schema_name()))
192192
}
193193

194194
/// Returns a full and complete string representation of this expression.

0 commit comments

Comments
 (0)