Skip to content

Commit a82a849

Browse files
author
Matt Roeschke
committed
Add regression test for DatetimeIndex.union mixed behavior
1 parent fb9c663 commit a82a849

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ Timezones
713713
- Bug in :func:`to_datetime` with ``unit='ns'`` would drop timezone information from the parsed argument (:issue:`26168`)
714714
- Bug in :func:`DataFrame.join` where joining a timezone aware index with a timezone aware column would result in a column of ``NaN`` (:issue:`26335`)
715715
- Bug in :func:`date_range` where ambiguous or nonexistent start or end times were not handled by the ``ambiguous`` or ``nonexistent`` keywords respectively (:issue:`27088`)
716+
- Bug in :meth:`DatetimeIndex.union` when combining a timezone aware and timezone unaware :class:`DatetimeIndex` (:issue:`21671`)
716717

717718
Numeric
718719
^^^^^^^

pandas/tests/indexes/datetimes/test_timezones.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,18 @@ def test_dti_union_aware(self):
10941094
assert result[0].tz.zone == 'US/Central'
10951095
assert result[-1].tz.zone == 'US/Eastern'
10961096

1097+
def test_dti_union_mixed(self):
1098+
# GH 21671
1099+
rng = DatetimeIndex([pd.Timestamp('2011-01-01'), pd.NaT])
1100+
rng2 = pd.DatetimeIndex(['2012-01-01', '2012-01-02'], tz='Asia/Tokyo')
1101+
result = rng.union(rng2)
1102+
expected = Index([pd.Timestamp('2011-01-01'),
1103+
pd.NaT,
1104+
pd.Timestamp('2012-01-01', tz='Asia/Tokyo'),
1105+
pd.Timestamp('2012-01-02', tz='Asia/Tokyo')],
1106+
dtype=object)
1107+
tm.assert_index_equal(result, expected)
1108+
10971109
@pytest.mark.parametrize('tz', [None, 'UTC', "US/Central",
10981110
dateutil.tz.tzoffset(None, -28800)])
10991111
@pytest.mark.usefixtures("datetime_tz_utc")

0 commit comments

Comments
 (0)