Skip to content

Commit

Permalink
BUG: box Timestamps in Series/DataFrame.iget_value. close #2148
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Nov 2, 2012
1 parent 8142167 commit fbb5c5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
============
Expand Down
19 changes: 12 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pandas/src/engines.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit fbb5c5e

Please sign in to comment.