Skip to content

Commit f3a02a4

Browse files
committed
BUG: don't lose time zone in DatetimeIndex.drop. close #2621
1 parent cb93c24 commit f3a02a4

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pandas 0.10.1
9191
but empty record list (GH2633_)
9292
- Fix C parser-tokenizer bug with trailing fields. (GH2668_)
9393
- Don't exclude non-numeric data from GroupBy.max/min (GH2700_)
94+
- Don't lose time zone when calling DatetimeIndex.drop (GH2621_)
9495

9596
**API Changes**
9697

@@ -108,6 +109,7 @@ pandas 0.10.1
108109
.. _GH2604: https://github.com/pydata/pandas/issues/2604
109110
.. _GH2576: https://github.com/pydata/pandas/issues/2576
110111
.. _GH2616: https://github.com/pydata/pandas/issues/2616
112+
.. _GH2621: https://github.com/pydata/pandas/issues/2621
111113
.. _GH2625: https://github.com/pydata/pandas/issues/2625
112114
.. _GH2643: https://github.com/pydata/pandas/issues/2643
113115
.. _GH2631: https://github.com/pydata/pandas/issues/2631

pandas/tseries/index.py

+11
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,17 @@ def insert(self, loc, item):
13461346
self[loc:].asi8))
13471347
return DatetimeIndex(new_index, freq='infer')
13481348

1349+
def delete(self, loc):
1350+
"""
1351+
Make new DatetimeIndex with passed location deleted
1352+
1353+
Returns
1354+
-------
1355+
new_index : DatetimeIndex
1356+
"""
1357+
arr = np.delete(self.values, loc)
1358+
return DatetimeIndex(arr, tz=self.tz)
1359+
13491360
def _view_like(self, ndarray):
13501361
result = ndarray.view(type(self))
13511362
result.offset = self.offset

pandas/tseries/tests/test_timezones.py

+6
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ def test_getitem_pydatetime_tz(self):
589589
tzinfo=pytz.timezone('Europe/Berlin'))
590590
self.assertEqual(ts[time_pandas], ts[time_datetime])
591591

592+
def test_index_drop_dont_lose_tz(self):
593+
# #2621
594+
ind = date_range("2012-12-01", periods=10, tz="utc")
595+
ind = ind.drop(ind[-1])
596+
597+
self.assertTrue(ind.tz is not None)
592598

593599
class TestTimeZones(unittest.TestCase):
594600
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)