Skip to content

[Python] error raised for TimestampScalar.__repr__() when timezone is set using offset "+00:00" #47043

Description

@zilto

Summary

A valid pyarrow.TimestampScalar value throws an error when its .__repr__() is called. This is specific to when timezones are specified as offsets +07:30. It doesn't occur with IANA "America/New_York" and UTC-like "UTC".

fromdatetimeimportdatetimeimportpyarrowpy_value=datetime(2012, 1, 1)
no_tz=pyarrow.scalar(py_value, type=pyarrow.timestamp("s"))
no_tz.__str__() # '2012-01-01 00:00:00'no_tz.__repr__() # "<pyarrow.TimestampScalar: '2012-01-01T00:00:00'>"no_tz.as_py().__repr__() # datetime(2012, 1, 1)utc_tz=pyarrow.scalar(py_value, type=pyarrow.timestamp("s", tz="UTC"))
utc_tz.__str__() # '2012-01-01 00:00:00'utc_tz.__repr__() # "<pyarrow.TimestampScalar: '2012-01-01T00:00:00'>"utc_tz.as_py().__repr__() # datetime(2012, 1, 1, tzinfo=<UTC>)offset_tz=pyarrow.scalar(py_value, type=pyarrow.timestamp("s", tz="+00:00"))
offset_tz.__str__() # '2012-01-01 00:00:00'offset_tz.__repr__()
# pyarrow.lib.ArrowInvalid: Cannot locate timezone '+00:00': +00:00 not found in timezone databaseoffset_tz.as_py().__repr__() # datetime(2012, 1, 1, tzinfo=<UTC>) # no error

note: I have limited understanding of cdef, .pyx, .pixi, etc.

Resources

Useful link and resources in my investigation:

Background

  • This bug was initially found via pyarrow.csv.CSVWriter().write() in the library Python dlt.
  • I initially thought it was related to the Python library ConnectorX which recently changed Rust backend from arrow2 to arrow (issue)
  • Pinned down the bug to Connectorx's change from specifying timezone via "UTC" to "+00:00" (why the change was made, the change)
  • Collaborating with Connectorx maintainers, we noticed that TimestampScalar.__str__() and TimestampScalar.__repr__() behaved differently

With this new knowledge, I will have to go back to dlt code for debugging. It's possible that there's no bug with the CSVWriter and what I encountered was the product of using the Python debugger to do the connector-x upgrade.

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