Skip to content

Commit

Permalink
BUG: TZ-aware Series.where() appropriately handles default other=nan (p…
Browse files Browse the repository at this point in the history
…andas-dev#15701)

closes pandas-dev#15701

Author: Christopher C. Aycock <christopher.aycock@twosigma.com>

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)
  • Loading branch information
Christopher C. Aycock authored and jreback committed Mar 17, 2017
1 parent 3ba68a7 commit de17fd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ Bug Fixes
- Bug in ``DataFrame.isin`` comparing datetimelike to empty frame (:issue:`15473`)

- Bug in ``Series.where()`` and ``DataFrame.where()`` where array-like conditionals were being rejected (:issue:`15414`)
- Bug in ``Series.where()`` where TZ-aware data was converted to float representation (:issue:`15701`)
- Bug in ``Index`` construction with ``NaN`` elements and integer dtype specified (:issue:`15187`)
- Bug in ``Series`` construction with a datetimetz (:issue:`14928`)
- Bug in output formatting of a ``MultiIndex`` when names are integers (:issue:`12223`, :issue:`15262`)
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,8 @@ def _try_coerce_args(self, values, other):

if isinstance(other, bool):
raise TypeError
elif is_null_datelike_scalar(other):
elif (is_null_datelike_scalar(other) or
(is_scalar(other) and isnull(other))):
other = tslib.iNaT
other_mask = True
elif isinstance(other, self._holder):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/series/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,14 @@ def test_where_datetime(self):
expected = Series([10, None], dtype='datetime64[ns]')
assert_series_equal(rs, expected)

# GH 15701
timestamps = ['2016-12-31 12:00:04+00:00',
'2016-12-31 12:00:04.010000+00:00']
s = Series([pd.Timestamp(t) for t in timestamps])
rs = s.where(Series([False, True]))
expected = Series([pd.NaT, s[1]])
assert_series_equal(rs, expected)

def test_where_timedelta(self):
s = Series([1, 2], dtype='timedelta64[ns]')
expected = Series([10, 10], dtype='timedelta64[ns]')
Expand Down

0 comments on commit de17fd9

Please sign in to comment.