jorisvandenbossche commented on pull request #11818:
URL: https://github.com/apache/arrow/pull/11818#issuecomment-1000236783


   > At the moment some of the code (ns, us, ms, s, m, h, d, w) is UTC based 
even when timezones are present. UTC always converts to a local time so 
nonexistent is not an issue while ambiguous could be.
   
   In pandas we always round in local time (some discussion about this in 
https://github.com/pandas-dev/pandas/issues/37592), and then you can actually 
run into nonexistent times as well. 
   The reason we do this (with its limitations ..), is because not every 
timezone has an exactly rounded / hourly offset, and so because of that 
rounding can give wrong results. For example, in Australia in summer there is a 
UTC+10:30 timezone:
   
   ```python
   >>> ts = pd.Timestamp("2021-07-01 12:17:00", tz="Australia/Lord_Howe")
   >>>ts
   Timestamp('2021-07-01 12:17:00+1030', tz='Australia/Lord_Howe')
   >>> ts.round("H")
   Timestamp('2021-07-01 12:00:00+1030', tz='Australia/Lord_Howe')
   
   # with this PR with pyarrow
   >>> arr = pa.array([ts])
   >>> pc.round_temporal(arr, unit="hour")
   <pyarrow.lib.TimestampArray object at 0x7f743c72dc40>
   [
     2021-07-01 02:00:00.000000
   ]
   >>> pc.round_temporal(arr, unit="hour")[0]
   <pyarrow.TimestampScalar: datetime.datetime(2021, 7, 1, 12, 30, 
tzinfo=<DstTzInfo 'Australia/Lord_Howe' +1030+10:30:00 STD>)>
   ```
   
   So with pyarrow that actually gives the "wrong" value now because of relying 
on rounding in UTC. 
   
   As I mentioned in the above-linked pandas issue, rounding in local time 
_does_ have some serious drawbacks (eg those annoying nonexistent times that 
actually should be possible to round properly without error), so it would be 
nice if we could somehow detect the cases where it is fine to do this. But 
doing that robustly might be quite complex ...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to