Changeset 1057
- Timestamp:
- 06/23/08 19:50:20 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/timeseries/scikits/timeseries/tests/test_timeseries.py
r1053 r1057 421 421 _wdates(series2D, data2D, dates[:3]) 422 422 423 def test_slicing_with_dates(self): 424 "Tests __getitem__ w/ date based slices" 425 def _testslice(series): 426 sd, ed = series.start_date, series.end_date 427 428 # full range of series 429 assert_equal(series, series[sd:ed+1]) 430 # exclude first and last point of series 431 assert_equal(series[1:-1], series[sd+1:ed]) 432 # slice with dates beyond the start and end dates 433 assert_equal(series, series[sd-10:ed+10]) 434 435 series = self.series1D 436 _testslice(series) 437 438 # now try slicing on a series with missing dates 439 series = series[::2] 440 _testslice(series) 423 441 424 442 def test_with_dates_as_str(self): … … 525 543 assert_equal(series._data, [5,1,2,3,5]) 526 544 assert_equal(series._mask, [0,0,0,0,0]) 527 545 528 546 # 529 547 def test_with_datearray(self): trunk/timeseries/scikits/timeseries/tseries.py
r1056 r1057 482 482 indx.step) 483 483 return (indx, indx, False) 484 484 485 if isinstance(indx, tuple): 485 486 if not self._varshape: … … 490 491 491 492 def _slicebound_checker(self, bound): 492 if isinstance(bound,int) or bound is None: 493 494 if bound is None or isinstance(bound, int): 493 495 return bound 496 494 497 _dates = self._dates 495 if isinstance(bound, (Date, DateArray)): 496 if bound.freq != _dates.freq: 497 raise TimeSeriesCompatibilityError('freq', 498 _dates.freq, bound.freq) 499 return _dates.date_to_index(bound) 500 if isinstance(bound, basestring): 501 return _dates.date_to_index(Date(_dates.freq, string=bound)) 502 498 if isinstance(bound, str): 499 bound = Date(_dates.freq, string=bound) 500 if not isinstance(bound, Date): 501 raise ValueError( 502 "invalid object used in slice: %s" % repr(bound)) 503 if bound.freq != _dates.freq: 504 raise TimeSeriesCompatibilityError('freq', 505 _dates.freq, bound.freq) 506 # this allows for slicing with dates outside the end points of the 507 # series and slicing on series with missing dates 508 return np.sum(self._dates < bound) 503 509 504 510 def __getitem__(self, indx):
