Skip to content

Commit

Permalink
BUG: work around NumPy 1.6.1 datetime64 bug, close #1561
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jul 11, 2012
1 parent 873409d commit 005b264
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pandas 0.8.1
- Selection of multiple SparseDataFrame columns by list in __getitem__ (#1585)
- Override Index.tolist for compatibility with MultiIndex (#1576)
- Fix hierarchical summing bug with MultiIndex of length 1 (#1568)
- Work around numpy.concatenate use/bug in Series.set_value (#1561)

pandas 0.8.0
============
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ def set_value(self, label, value):
self.index._engine.set_value(self, label, value)
return self
except KeyError:
new_index = np.concatenate([self.index.values, [label]])
if len(self.index) == 0:
new_index = Index([label])
else:
new_index = self.index.insert(len(self), label)

new_values = np.concatenate([self.values, [value]])
return Series(new_values, index=new_index, name=self.name)

Expand Down
16 changes: 15 additions & 1 deletion pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,22 @@ def test_datetimeindex_union_join_empty(self):
result = dti.join(empty)
self.assert_(isinstance(result, DatetimeIndex))

# TODO: test merge & concat with datetime64 block
def test_series_set_value(self):
# #1561

dates = [datetime(2001, 1, 1), datetime(2001, 1, 2)]
index = DatetimeIndex(dates)

s = Series().set_value(dates[0], 1.)
s2 = s.set_value(dates[1], np.nan)

exp = Series([1., np.nan], index=index)

assert_series_equal(s2, exp)

# s = Series(index[:1], index[:1])
# s2 = s.set_value(dates[1], index[1])
# self.assert_(s2.values.dtype == 'M8[ns]')

class TestSeriesDatetime64(unittest.TestCase):

Expand Down

0 comments on commit 005b264

Please sign in to comment.