diff --git a/RELEASE.rst b/RELEASE.rst index 7612c26292f75..321f16535f9ae 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -56,6 +56,7 @@ pandas 0.9.1 - Alias Timestamp.astimezone to tz_convert, so will yield Timestamp (#2060) - Fix timedelta64 formatting from Series (#2165, #2146) - Handle None values gracefully in dict passed to Panel constructor (#2075) + - Box datetime64 values as Timestamp objects in Series/DataFrame.iget (#2148) pandas 0.9.0 ============ diff --git a/pandas/core/series.py b/pandas/core/series.py index 54e5255a554a6..1b105d48f4dbe 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -734,14 +734,19 @@ def iget_value(self, i): ------- value : scalar (int) or Series (slice, sequence) """ - if isinstance(i, slice): - return self[i] - else: - label = self.index[i] - if isinstance(label, Index): - return self.reindex(label) + try: + return lib.get_value_at(self, i) + except IndexError: + raise + except: + if isinstance(i, slice): + return self[i] else: - return lib.get_value_at(self, i) + label = self.index[i] + if isinstance(label, Index): + return self.reindex(label) + else: + return lib.get_value_at(self, i) iget = iget_value irow = iget_value diff --git a/pandas/src/engines.pyx b/pandas/src/engines.pyx index ca0a9107486a4..a564cbafae7ab 100644 --- a/pandas/src/engines.pyx +++ b/pandas/src/engines.pyx @@ -39,6 +39,8 @@ cdef inline is_definitely_invalid_key(object val): or PyList_Check(val)) def get_value_at(ndarray arr, object loc): + if arr.descr.type_num == NPY_DATETIME: + return Timestamp(util.get_value_at(arr, loc)) return util.get_value_at(arr, loc) def set_value_at(ndarray arr, object loc, object val): diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index e27045ba6119c..eabacc2222ebf 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -216,6 +216,8 @@ def test_series_box_timestamp(self): s = Series(rng, index=rng) self.assert_(isinstance(s[5], Timestamp)) + self.assert_(isinstance(s.iget_value(5), Timestamp)) + def test_timestamp_to_datetime(self): _skip_if_no_pytz() rng = date_range('20090415', '20090519',