Skip to content

BUG: Fix subtraction with timezone Series #12302

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

Closed
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
4 changes: 2 additions & 2 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ def _offset(lvalues, rvalues):

# with tz, convert to UTC
if self.is_datetime64tz_lhs:
lvalues = lvalues.tz_localize(None)
lvalues = lvalues.tz_convert('UTC')
if self.is_datetime64tz_rhs:
rvalues = rvalues.tz_localize(None)
rvalues = rvalues.tz_convert('UTC')

lvalues = lvalues.view(np.int64)
rvalues = rvalues.view(np.int64)
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/series/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,3 +1375,18 @@ def test_datetime64_with_index(self):
df['expected'] = df['date'] - df.index.to_series()
df['result'] = df['date'] - df.index
assert_series_equal(df['result'], df['expected'], check_names=False)

# See gh-12290
def test_datetime64_single_non_native(self):
f = Series([pd.Timestamp('2016-02-08 13:43:14.605000',
tz='America/Sao_Paulo')])
s = Series([pd.Timestamp('2016-02-10 13:43:14.605000',
tz='America/Sao_Paulo')])

out = f - s
expected = Series(pd.Timedelta('-2days'))
assert_series_equal(out, expected)

out = s - f
expected = Series(pd.Timedelta('2days'))
assert_series_equal(out, expected)