Skip to content

Commit b6e4645

Browse files
Michael-J-Wardemgeee
authored andcommitted
deprecate Expr::display_name
Ref: apache/datafusion#11797
1 parent cd04c44 commit b6e4645

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

python/datafusion/expr.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030
from datafusion.common import NullTreatment, RexType, DataTypeMap
3131
from typing import Any, Optional, Type
32+
from typing_extensions import deprecated
3233
import pyarrow as pa
3334

3435
# The following are imported from the internal representation. We may choose to
@@ -195,12 +196,20 @@ def to_variant(self) -> Any:
195196
"""Convert this expression into a python object if possible."""
196197
return self.expr.to_variant()
197198

199+
@deprecated(since="41.0.0", message="Use :py:meth:`~Expr.schema_name` instead")
198200
def display_name(self) -> str:
199201
"""Returns the name of this expression as it should appear in a schema.
200202
201203
This name will not include any CAST expressions.
202204
"""
203-
return self.expr.display_name()
205+
return self.schema_name()
206+
207+
def schema_name(self) -> str:
208+
"""Returns the name of this expression as it should appear in a schema.
209+
210+
This name will not include any CAST expressions.
211+
"""
212+
return self.expr.schema_name()
204213

205214
def canonical_name(self) -> str:
206215
"""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
@@ -192,3 +192,23 @@ def test_expr_getitem() -> None:
192192

193193
assert names == ["Alice", "Bob", "Charlie", None]
194194
assert array_values == [2, 5, None, None]
195+
196+
197+
def test_display_name_deprecation():
198+
import warnings
199+
expr = col("foo")
200+
with warnings.catch_warnings(record=True) as w:
201+
# Cause all warnings to always be triggered
202+
warnings.simplefilter("always")
203+
204+
# should trigger warning
205+
name = expr.display_name()
206+
207+
# Verify some things
208+
assert len(w) == 1
209+
assert issubclass(w[-1].category, DeprecationWarning)
210+
assert "deprecated" in str(w[-1].message)
211+
212+
# returns appropriate result
213+
assert name == expr.schema_name()
214+
assert name == "foo"

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl PyExpr {
189189

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

0 commit comments

Comments
 (0)