Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-15026

[Python] datetime.timedelta to pyarrow.duration('us') silently overflows

    XMLWordPrintableJSON

Details

    Description

       

      Hi! This reproduces the issue:

      # python 3.9.9
      # pyarrow 6.0.1
      import datetime
      import pyarrow
      d = datetime.timedelta(days=-106751992, seconds=71945, microseconds=224192)
      pyarrow.scalar(d)
      # <pyarrow.DurationScalar: datetime.timedelta(days=-106751992, seconds=71945, microseconds=224192)>
      pyarrow.scalar(d).as_py() == d
      # True
      d2 = d - datetime.timedelta(microseconds=1)
      pyarrow.scalar(d2)
      # <pyarrow.DurationScalar: datetime.timedelta(days=106751991, seconds=14454, microseconds=775807)>
      pyarrow.scalar(d2).as_py() == d2
      # False

      Other conversions (e.g. to int*) raise an exception instead. I didn't check if duration overflows for too large timedeltas. If its easy to fix, point me in the right direction and I try to create a PR. Thanks

       

      Attachments

        Issue Links

          Activity

            People

              anjakefala Anja Boskovic
              !evil Andreas Rappold
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h
                  3h