Skip to content

[Python] pyarrow.compute.strftime silently echoes unsupported format specifiers (%s returns the literal '%s') #51499

Description

@ptimizeroracle

Describe the bug

pyarrow.compute.strftime passes unsupported format specifiers through literally instead of either formatting them or raising. %s (epoch seconds, a widely used strftime extension) returns the format string itself as the data:

>>> import pyarrow as pa, pyarrow.compute as pc
>>> from datetime import datetime
>>> d = pa.array([datetime(2021, 1, 1, 12, 30, 45)])
>>> pc.strftime(d, format="%s").to_pylist()
['%s']
>>> int(datetime(2021, 1, 1, 12, 30, 45).timestamp())  # expected
1609500645

polars and duckdb both return the epoch value for %s, and raising would also be acceptable, but silently returning '%s' as column data means downstream code consumes the format string as if it were real data with no error anywhere.

(side observation on the same kernel: %S returns '45.000000' rather than the two-digit '45', which also diverges from strftime conventions, but the %s case is the silent-data-corruption one)

Component(s)

Python

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions