From b6e464592a840027d4cd4392b086a041802f65d1 Mon Sep 17 00:00:00 2001 From: Michael-J-Ward Date: Sat, 10 Aug 2024 15:33:41 -0500 Subject: [PATCH] deprecate Expr::display_name Ref: https://github.com/apache/datafusion/pull/11797 --- python/datafusion/expr.py | 11 ++++++++++- python/datafusion/tests/test_expr.py | 20 ++++++++++++++++++++ src/expr.rs | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/python/datafusion/expr.py b/python/datafusion/expr.py index 78acee31b..1733e69ac 100644 --- a/python/datafusion/expr.py +++ b/python/datafusion/expr.py @@ -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 @@ -195,12 +196,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.""" diff --git a/python/datafusion/tests/test_expr.py b/python/datafusion/tests/test_expr.py index 056d2ea03..1aa93110c 100644 --- a/python/datafusion/tests/test_expr.py +++ b/python/datafusion/tests/test_expr.py @@ -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" diff --git a/src/expr.rs b/src/expr.rs index 4841b26b1..e1edbe864 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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 { + fn schema_name(&self) -> PyResult { Ok(format!("{}", self.expr.schema_name())) }