Skip to content

Commit de17fd9

Browse files
Christopher C. Aycockjreback
Christopher C. Aycock
authored andcommitted
BUG: TZ-aware Series.where() appropriately handles default other=nan (pandas-dev#15701)
closes pandas-dev#15701 Author: Christopher C. Aycock <[email protected]> Closes pandas-dev#15711 from chrisaycock/GH15701 and squashes the following commits: b77f5ed [Christopher C. Aycock] BUG: TZ-aware Series.where() appropriately handles default other=nan (pandas-dev#15701)
1 parent 3ba68a7 commit de17fd9

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ Bug Fixes
829829
- Bug in ``DataFrame.isin`` comparing datetimelike to empty frame (:issue:`15473`)
830830

831831
- Bug in ``Series.where()`` and ``DataFrame.where()`` where array-like conditionals were being rejected (:issue:`15414`)
832+
- Bug in ``Series.where()`` where TZ-aware data was converted to float representation (:issue:`15701`)
832833
- Bug in ``Index`` construction with ``NaN`` elements and integer dtype specified (:issue:`15187`)
833834
- Bug in ``Series`` construction with a datetimetz (:issue:`14928`)
834835
- Bug in output formatting of a ``MultiIndex`` when names are integers (:issue:`12223`, :issue:`15262`)

pandas/core/internals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,8 @@ def _try_coerce_args(self, values, other):
24402440

24412441
if isinstance(other, bool):
24422442
raise TypeError
2443-
elif is_null_datelike_scalar(other):
2443+
elif (is_null_datelike_scalar(other) or
2444+
(is_scalar(other) and isnull(other))):
24442445
other = tslib.iNaT
24452446
other_mask = True
24462447
elif isinstance(other, self._holder):

pandas/tests/series/test_indexing.py

+8
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,14 @@ def test_where_datetime(self):
13851385
expected = Series([10, None], dtype='datetime64[ns]')
13861386
assert_series_equal(rs, expected)
13871387

1388+
# GH 15701
1389+
timestamps = ['2016-12-31 12:00:04+00:00',
1390+
'2016-12-31 12:00:04.010000+00:00']
1391+
s = Series([pd.Timestamp(t) for t in timestamps])
1392+
rs = s.where(Series([False, True]))
1393+
expected = Series([pd.NaT, s[1]])
1394+
assert_series_equal(rs, expected)
1395+
13881396
def test_where_timedelta(self):
13891397
s = Series([1, 2], dtype='timedelta64[ns]')
13901398
expected = Series([10, 10], dtype='timedelta64[ns]')

0 commit comments

Comments
 (0)