Skip to content

Add deprecation warnings for Expr passed to confirmed literal-only function arguments#1605

Open
kosiew wants to merge 2 commits into
apache:mainfrom
kosiew:deprecation-typehint-02-1496
Open

Add deprecation warnings for Expr passed to confirmed literal-only function arguments#1605
kosiew wants to merge 2 commits into
apache:mainfrom
kosiew:deprecation-typehint-02-1496

Conversation

@kosiew

@kosiew kosiew commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

As part of the audit of Expr | literal function arguments, this change targets a set of arguments that act as control/configuration parameters rather than row-varying data expressions. These arguments are intended to be provided as Python literals (for example, encoding names, digest methods, data type specifiers, and metadata keys).

To prepare for future API cleanup while preserving compatibility, passing an Expr to these arguments now emits a DeprecationWarning but continues to work.

What changes are included in this PR?

  • Added a reusable helper, _warn_if_expr_for_literal_arg, that emits a deprecation warning when an Expr is supplied to a confirmed literal-only argument.

  • Added deprecation warnings for the following function arguments:

    • encode(..., encoding=...)
    • decode(..., encoding=...)
    • digest(..., method=...)
    • arrow_cast(..., data_type=...)
    • arrow_try_cast(..., data_type=...)
    • arrow_metadata(..., key=...)
  • Preserved existing behavior by continuing to coerce these values to expressions after warning.

  • Added tests covering both warning and non-warning cases.

Are these changes tested?

Yes.

Added tests in python/tests/test_functions.py that verify:

  • Passing literal(...) / Expr values to the audited literal-only arguments emits a DeprecationWarning.

  • Passing native Python literal values does not emit a DeprecationWarning.

  • Coverage includes:

    • encode
    • decode
    • digest
    • arrow_cast
    • arrow_try_cast
    • arrow_metadata

Are there any user-facing changes?

Yes.

Users will now receive a DeprecationWarning when passing an Expr to the following literal-only arguments:

  • encode(..., encoding=...)
  • decode(..., encoding=...)
  • digest(..., method=...)
  • arrow_cast(..., data_type=...)
  • arrow_try_cast(..., data_type=...)
  • arrow_metadata(..., key=...)

Existing behavior is otherwise unchanged, and Python literal inputs remain fully supported without warnings.

LLM-generated code disclosure

This PR includes code, comments generated with assistance from LLM. All LLM-generated content has been manually reviewed.

kosiew added 2 commits June 18, 2026 16:45
- Introduced shared `_warn_if_expr_for_literal_arg` in `functions/__init__.py`
- Added `DeprecationWarning` for the following methods when `Expr` is passed as argument:
- `encode(..., encoding=Expr)`
- `decode(..., encoding=Expr)`
- `digest(..., method=Expr)`
- `arrow_cast(..., data_type=Expr)`
- `arrow_try_cast(..., data_type=Expr)`
- `arrow_metadata(..., key=Expr)`

test: update tests to check for warnings

- Implemented tests in `test_functions.py` to ensure:
- Warning is raised for `Expr` form
- No warning for native literal form
@kosiew kosiew marked this pull request as ready for review June 18, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant