[
https://issues.apache.org/jira/browse/ARROW-1906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16286013#comment-16286013
]
ASF GitHub Bot commented on ARROW-1906:
---------------------------------------
wesm closed pull request #1411: ARROW-1906: [Python] Do not override
user-supplied type in pyarrow.array when converting DatetimeTZ pandas data
URL: https://github.com/apache/arrow/pull/1411
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py
index 668048fd6..42c71b039 100644
--- a/python/pyarrow/pandas_compat.py
+++ b/python/pyarrow/pandas_compat.py
@@ -369,7 +369,8 @@ def get_datetimetz_type(values, dtype, type_):
if values.dtype.type != np.datetime64:
return values, type_
- if isinstance(dtype, DatetimeTZDtype):
+ if isinstance(dtype, DatetimeTZDtype) and type_ is None:
+ # If no user type passed, construct a tz-aware timestamp type
tz = dtype.tz
unit = dtype.unit
type_ = pa.timestamp(unit, tz)
diff --git a/python/pyarrow/tests/test_array.py
b/python/pyarrow/tests/test_array.py
index 92562da14..fa38c9257 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -331,8 +331,12 @@ def test_cast_timestamp_unit():
s_nyc = s.dt.tz_localize('tzlocal()').dt.tz_convert('America/New_York')
us_with_tz = pa.timestamp('us', tz='America/New_York')
+
arr = pa.Array.from_pandas(s_nyc, type=us_with_tz)
+ # ARROW-1906
+ assert arr.type == us_with_tz
+
arr2 = pa.Array.from_pandas(s, type=pa.timestamp('us'))
assert arr[0].as_py() == s_nyc[0]
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [Python] Creating a pyarrow.Array with timestamp of different unit is not
> casted
> --------------------------------------------------------------------------------
>
> Key: ARROW-1906
> URL: https://issues.apache.org/jira/browse/ARROW-1906
> Project: Apache Arrow
> Issue Type: Bug
> Components: Python
> Reporter: Bryan Cutler
> Assignee: Wes McKinney
> Labels: pull-request-available
> Fix For: 0.8.0
>
>
> This is similar to ARROW-1680 but slightly different in that an error is not
> raised but the unit will still remain unchanged only when using a timezone
> {noformat}
> In [47]: us_with_tz = pa.timestamp('us', tz='America/New_York')
> In [48]: s = pd.Series([val])
> In [49]: s_nyc =
> s.dt.tz_localize('tzlocal()').dt.tz_convert('America/New_York')
> In [50]: arr = pa.Array.from_pandas(s_nyc, type=us_with_tz)
> In [51]: arr.type
> Out[51]: TimestampType(timestamp[ns, tz=America/New_York])
> In [52]: arr2 = pa.Array.from_pandas(s, type=pa.timestamp('us'))
> In [53]: arr2.type
> Out[53]: TimestampType(timestamp[us])
> {noformat}
> There is an easy workaround to apply the cast after creating the
> pyarrow.Array, which seems to work fine
> {noformat}
> In [54]: arr = pa.Array.from_pandas(s_nyc).cast(us_with_tz, safe=False)
> In [55]: arr.type
> Out[55]: TimestampType(timestamp[us, tz=America/New_York])
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)