Skip to content

Commit 273bfb0

Browse files
kawochenjreback
authored andcommitted
BUG: GH12290 where tz_convert used values of uninitialized arrays
closes #12290 Author: Ka Wo Chen <[email protected]> Closes #12306 from kawochen/BUG-FIX-12290 and squashes the following commits: 38bed4d [Ka Wo Chen] BUG: GH12290 where tz_convert used values of uninitialized arrays
1 parent 0c09bd1 commit 273bfb0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ Bug Fixes
906906

907907

908908
- Bug in ``NaT`` subtraction from ``Timestamp`` or ``DatetimeIndex`` with timezones (:issue:`11718`)
909+
- Bug in subtraction of ``Series`` of a single tz-aware ``Timestamp`` (:issue:`12290`)
909910

910911
- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
911912
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)

pandas/tests/series/test_operators.py

+11
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,17 @@ def run_ops(ops, get_ser, test_ser):
660660
self.assertRaises(TypeError, lambda: td1 - dt1)
661661
self.assertRaises(TypeError, lambda: td2 - dt2)
662662

663+
def test_sub_single_tz(self):
664+
# GH12290
665+
s1 = Series([pd.Timestamp('2016-02-10', tz='America/Sao_Paulo')])
666+
s2 = Series([pd.Timestamp('2016-02-08', tz='America/Sao_Paulo')])
667+
result = s1 - s2
668+
expected = Series([Timedelta('2days')])
669+
assert_series_equal(result, expected)
670+
result = s2 - s1
671+
expected = Series([Timedelta('-2days')])
672+
assert_series_equal(result, expected)
673+
663674
def test_ops_nat(self):
664675
# GH 11349
665676
timedelta_series = Series([NaT, Timedelta('1s')])

pandas/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
35303530
if _get_zone(tz2) == 'UTC':
35313531
return utc_dates
35323532

3533-
result = np.empty(n, dtype=np.int64)
3533+
result = np.zeros(n, dtype=np.int64)
35343534
if _is_tzlocal(tz2):
35353535
for i in range(n):
35363536
v = utc_dates[i]

0 commit comments

Comments
 (0)