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 Sep 10, 2024
1 parent 8888848 commit 2cb04b9
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 @@ -29,6 +29,7 @@
)
from datafusion.common import NullTreatment, RexType, DataTypeMap
from typing import Any, Optional, Type
from typing_extensions import deprecated
import pyarrow as pa

# The following are imported from the internal representation. We may choose to
Expand Down Expand Up @@ -174,12 +175,20 @@ def to_variant(self) -> Any:
"""Convert this expression into a python object if possible."""
return self.expr.to_variant()

@deprecated(since="41.0.0", message="Use :py:meth:`~Expr.schema_name` instead")
def display_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.display_name()
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 @@ -192,3 +192,23 @@ def test_expr_getitem() -> None:

assert names == ["Alice", "Bob", "Charlie", None]
assert array_values == [2, 5, None, None]


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 @@ -188,8 +188,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 2cb04b9

Please sign in to comment.