Changeset 1203
- Timestamp:
- 08/06/08 19:39:41 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/timeseries/scikits/timeseries/tests/test_timeseries.py
r1169 r1203 512 512 assert_equal(piece._fill_value, -9999) 513 513 assert_equal(piece[:5]._basedict['info'], '???') 514 514 515 515 516 516 class TestSetItem(TestCase): … … 555 555 assert_equal(series._data, [5,1,2,3,5]) 556 556 assert_equal(series._mask, [0,0,0,0,0]) 557 558 # test for bug fixed in r1203 559 x, y = ts.now('b'), ts.now('b')+1 560 a = ts.time_series([1], start_date=x) 561 b = ts.time_series([4,5], start_date=x) 562 b[x:y] = a[x:y] 563 assert_equal(b[0], 1) 557 564 558 565 # … … 603 610 test1D = series1D.reshape(*newshape) 604 611 assert_equal(test1D.shape, newshape) 605 612 606 613 # 607 614 def test_reshaping_2D(self): trunk/timeseries/scikits/timeseries/tseries.py
r1202 r1203 564 564 Sets item described by index. If value is masked, masks those locations. 565 565 """ 566 if self is masked:567 raise MAError, 'Cannot alter the masked element.'566 (sindx, dindx, recheck) = self._index_checker(indx) 567 _dates = ndarray.__getattribute__(self, '_dates') 568 568 try: 569 MaskedArray.__setitem__(self, indx, value)569 MaskedArray.__setitem__(self, sindx, value) 570 570 except IndexError: 571 # Easy case: we're out of bounds...572 if isinstance(indx, int):571 # We don't need to recheck the index: just raise an exception 572 if not recheck: 573 573 raise 574 # Mmh, is the index a (list of) Date(s) ? 575 _dates = ndarray.__getattribute__(self, '_dates') 574 # Maybe the index is a list of Dates ? 576 575 try: 577 indx = _dates.date_to_index(date_array(indx, freq=self.freq)) 578 except: 579 raise 576 indx = _dates.date_to_index(indx) 577 except (IndexError, ValueError): 578 # Mmh, is it a list of dates as strings ? 579 try: 580 indx = _dates.date_to_index(date_array(indx, 581 freq=_dates.freq)) 582 except (IndexError, ValueError, DateError): 583 exc_info = sys.exc_info() 584 msg = "Invalid index or date '%s'" % indx 585 raise IndexError(msg), None, exc_info[2] 586 else: 587 MaskedArray.__setitem__(self, indx, value) 580 588 else: 581 589 MaskedArray.__setitem__(self, indx, value) 582 except ValueError:583 # OK, that should be a slice, then...584 if isinstance(indx, slice):585 sindx = slice(self._slicebound_checker(indx.start),586 self._slicebound_checker(indx.stop),587 indx.step)588 # Or maybe a field?589 elif isinstance(indx, basestring) and \590 self.dtype.names is not None and indx in self.dtype.names:591 sindx = indx592 # or string representation of a Date?593 elif isinstance(indx, basestring):594 _date = Date(freq=self.freq, string=indx)595 _dates = ndarray.__getattribute__(self, '_dates')596 sindx = _dates.date_to_index(_date)597 # Or some kind of date...598 else:599 _dates = ndarray.__getattribute__(self, '_dates')600 sindx = _dates.date_to_index(date_array(indx, freq=self.freq))601 #602 try:603 MaskedArray.__setitem__(self, sindx, value)604 except IndexError:605 raise IndexError("Date '%s' out of bounds !" % indx)606 590 607 591 def __setattr__(self, attr, value):
