Skip to content

Commit

Permalink
deprecate Expr::display_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-J-Ward committed Aug 10, 2024
1 parent 14f18ad commit a09d848
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
11 changes: 10 additions & 1 deletion python/datafusion/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
20 changes: 20 additions & 0 deletions python/datafusion/tests/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Ok(self.expr.display_name()?)
fn schema_name(&self) -> PyResult<String> {
Ok(format!("{}", self.expr.schema_name()))
}

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

0 comments on commit a09d848

Please sign in to comment.