Skip to content

Commit 2cb04b9

Browse files
deprecate Expr::display_name
Ref: apache/datafusion#11797
1 parent 8888848 commit 2cb04b9

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
@@ -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
@@ -174,12 +175,20 @@ def to_variant(self) -> Any:
174175
"""Convert this expression into a python object if possible."""
175176
return self.expr.to_variant()
176177

178+
@deprecated(since="41.0.0", message="Use :py:meth:`~Expr.schema_name` instead")
177179
def display_name(self) -> str:
178180
"""Returns the name of this expression as it should appear in a schema.
179181
180182
This name will not include any CAST expressions.
181183
"""
182-
return self.expr.display_name()
184+
return self.schema_name()
185+
186+
def schema_name(self) -> str:
187+
"""Returns the name of this expression as it should appear in a schema.
188+
189+
This name will not include any CAST expressions.
190+
"""
191+
return self.expr.schema_name()
183192

184193
def canonical_name(self) -> str:
185194
"""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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ impl PyExpr {
188188

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

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

0 commit comments

Comments
 (0)