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 authored and emgeee committed Sep 10, 2024
1 parent cd04c44 commit afcc9f1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 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 @@ -195,12 +196,20 @@ def to_variant(self) -> Any:
"""Convert this expression into a python object if possible."""
return self.expr.to_variant()

@deprecated("display_name() is deprecated. 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"
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ 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> {
fn schema_name(&self) -> PyResult<String> {
Ok(format!("{}", self.expr.schema_name()))
}

Expand Down

0 comments on commit afcc9f1

Please sign in to comment.