AlenkaF opened a new pull request, #14448:
URL: https://github.com/apache/arrow/pull/14448

   This PR tries to substitute `fromutc` method in `ConvertTimezoneAware ` 
(arrow_to_pandas.cc) as it errors when `tzinfo` is an instance of `pytz` 
timezone. Basically does the change from:
   ```python
   tzinfo.fromutc(dt)
   ```
   to
   ```python
   dt.replace(tzinfo=datetime.timezone.utc).astimezone(tzinfo)
   ```
   but in C++.
   
   ---
   At the moment there is an error in conversion and am looking into the reason 
behind it. I get a random shift in date and time when calling 
"[astimezone](https://github.com/AlenkaF/arrow/blob/a1c7955529c91fa672c80e4939bf39330f1ade6f/python/pyarrow/src/arrow/python/arrow_to_pandas.cc#L1086)".
   
   ```python
   import pyarrow as pa
   import datetime 
   import pytz
   
   tz = pytz.FixedOffset(120)
   ts = tz.localize(datetime.datetime(2022, 5, 12, 16, 57))
   timestamps = pa.array([ts])
   names = ["timestamp_col"]
   table = pa.Table.from_arrays([timestamps], names=names)
   
   table.to_pandas()
   #               timestamp_col
   # 0 2022-05-12 16:57:00+02:00
   
   table.to_pandas(timestamp_as_object=True)
   #                timestamp_col
   # 0  2022-05-12 14:57:00+02:00
   
   from zoneinfo import ZoneInfo
   ts2 = datetime.datetime(2021, 1, 1, tzinfo=ZoneInfo("America/Los_Angeles"))
   timestamps = pa.array([ts2])
   names = ["timestamp_col"]
   table = pa.Table.from_arrays([timestamps], names=names)
   
   
   table.to_pandas()
   #              timestamp_col
   # 0 2021-01-01 00:00:00-08:00
   
   table.to_pandas(timestamp_as_object=True)
   #                timestamp_col
   # 0  2020-12-31 23:00:00-08:00
   ```


-- 
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