Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-1906: [Python] Do not override user-supplied type in pyarrow.array when converting DatetimeTZ pandas data #1411

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/pyarrow/pandas_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down