Skip to content

Commit c91425b

Browse files
BUG: fix tz-aware datetime convert to DatetimeIndex (GH 14088)
1 parent 185fcbe commit c91425b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ Bug Fixes
12361236
- Bug where ``pd.read_gbq()`` could throw ``ImportError: No module named discovery`` as a result of a naming conflict with another python package called apiclient (:issue:`13454`)
12371237
- Bug in ``Index.union`` returns an incorrect result with a named empty index (:issue:`13432`)
12381238
- Bugs in ``Index.difference`` and ``DataFrame.join`` raise in Python3 when using mixed-integer indexes (:issue:`13432`, :issue:`12814`)
1239+
- Bug in subtract tz-aware ``datetime.datetime`` from tz-aware ``datetime64`` series (:issue:`14088`)
12391240
- Bug in ``.to_excel()`` when DataFrame contains a MultiIndex which contains a label with a NaN value (:issue:`13511`)
12401241
- Bug in invalid frequency offset string like "D1", "-2-3H" may not raise ``ValueError (:issue:`13930`)
12411242
- Bug in ``concat`` and ``groupby`` for hierarchical frames with ``RangeIndex`` levels (:issue:`13542`).

pandas/core/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def _convert_to_array(self, values, name=None, other=None):
453453
values = values.to_series()
454454
# datetime with tz
455455
elif (isinstance(ovalues, datetime.datetime) and
456-
hasattr(ovalues, 'tz')):
456+
hasattr(ovalues, 'tzinfo')):
457457
values = pd.DatetimeIndex(values)
458458
# datetime array with tz
459459
elif is_datetimetz(values):

pandas/tests/series/test_operators.py

+8
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ def test_operators_timedelta64(self):
267267
rs[2] += np.timedelta64(timedelta(minutes=5, seconds=1))
268268
self.assertEqual(rs[2], value)
269269

270+
# GH 14088
271+
import pytz
272+
s = Series([datetime(2016, 8, 23, 12, tzinfo=pytz.utc), pd.NaT])
273+
dt = datetime(2016, 8, 22, 12, tzinfo=pytz.utc)
274+
exp = Series([Timedelta('1 days'), pd.NaT])
275+
self.assert_series_equal(s - dt, exp)
276+
self.assert_series_equal(s - Timestamp(dt), exp)
277+
270278
def test_operator_series_comparison_zerorank(self):
271279
# GH 13006
272280
result = np.float64(0) > pd.Series([1, 2, 3])

0 commit comments

Comments
 (0)