AlenkaF commented on a change in pull request #11574:
URL: https://github.com/apache/arrow/pull/11574#discussion_r742580012



##########
File path: python/pyarrow/scalar.pxi
##########
@@ -395,7 +395,7 @@ def _datetime_from_int(int64_t value, TimeUnit unit, 
tzinfo=None):
     dt = datetime.datetime(1970, 1, 1) + delta
     # adjust timezone if set to the datatype
     if tzinfo is not None:
-        dt = tzinfo.fromutc(dt)
+        dt = tzinfo.fromutc(dt.replace(tzinfo=tzinfo))

Review comment:
       It should work the same but the change produces an error in the test (at 
the end).
   
   ```
   >>> import pytz
   >>> import datetime
   >>> tzinfo = pytz.FixedOffset(120)
   >>> tzinfo
   pytz.FixedOffset(120)
   >>> pytz.FixedOffset(120)
   pytz.FixedOffset(120)
   >>> 
   >>> dt = datetime.datetime(2021, 1, 1)
   >>> tzinfo.fromutc(dt.replace(tzinfo=tzinfo))
   datetime.datetime(2021, 1, 1, 2, 0, tzinfo=pytz.FixedOffset(120))
   >>> dt.replace(tzinfo=datetime.timezone.utc).astimezone(tzinfo)
   datetime.datetime(2021, 1, 1, 2, 0, tzinfo=pytz.FixedOffset(120))
   >>> 
   >>> 
   >>> arr = pa.array([0], pa.timestamp('s', tz='+02:00'))
   >>> str(arr[0])
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "pyarrow/scalar.pxi", line 89, in pyarrow.lib.Scalar.__str__
       return str(self.as_py())
     File "pyarrow/scalar.pxi", line 469, in pyarrow.lib.TimestampScalar.as_py
       return _datetime_from_int(sp.value, unit=dtype.unit(), tzinfo=tzinfo)
     File "pyarrow/scalar.pxi", line 398, in pyarrow.lib._datetime_from_int
       dt = dt.replace(tzinfo=datetime.timezone.utc).astimezone(tzinfo)
   ValueError: fromutc: dt.tzinfo is not self
   ```
   
   Suggest we leave it as it is.




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