示例#1
0
 def test_does_not_contain_slice_completely_after(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(200))
     ts2 = TimeSlice(Seconds(100), Seconds(310))
     self.assertFalse(ts2 in ts1)
示例#2
0
 def test_contains_point_in_time_during(self):
     ts = TimeSlice(Seconds(100), start=Seconds(200))
     self.assertTrue(Seconds(210) in ts)
示例#3
0
 def end(self):
     try:
         return self._data.timeslice[-1].end
     except IndexError:
         return Seconds(0)
示例#4
0
 def test_can_intersect_two_time_slices(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(100))
     ts2 = TimeSlice(Seconds(100), start=Seconds(101))
     intersection = ts1 & ts2
     self.assertEqual(Seconds(99), intersection.duration)
示例#5
0
 def test_seconds_equal(self):
     a = Seconds(1)
     b = np.timedelta64(1, 's')
     self.assertEqual(a, b)
示例#6
0
 def test_samplerate_one_per_second(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     self.assertEqual(1, ts.dimensions[0].samples_per_second)
示例#7
0
 def test_can_repr_open_ended_slice(self):
     r = repr(TimeSlice(start=Seconds(2)))
     self.assertIsNotNone(r)
示例#8
0
 def test_can_slice_time_series_with_negative_end_time(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     sliced = ts[:-Seconds(2)]
     self.assertEqual(8, len(sliced))
示例#9
0
 def test_can_index_constant_rate_time_series_with_integer_index(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     ts2 = ts[5]
     self.assertEqual(5, ts2)
示例#10
0
 def test_ne_when_starts_differ(self):
     ts1 = TimeSlice(Seconds(2), start=Seconds(2))
     ts2 = TimeSlice(Seconds(2), start=Seconds(3))
     self.assertNotEqual(ts1, ts2)
示例#11
0
 def test_can_slice_time_series_with_start_and_end_time(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     sliced = ts[Seconds(5):Seconds(7)]
     self.assertEqual(2, len(sliced))
示例#12
0
 def test_eq_when_start_and_duration_equal(self):
     ts1 = TimeSlice(Seconds(2), start=Seconds(2))
     ts2 = TimeSlice(Seconds(2), start=Seconds(2))
     self.assertEqual(ts1, ts2)
示例#13
0
 def test_raises_value_error_if_item_is_not_timedelta_or_timeslice(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(200))
     self.assertRaises(ValueError, lambda: 's' in ts1)
示例#14
0
 def test_does_not_contain_slice_beginning_after(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(200))
     ts2 = TimeSlice(Seconds(100), Seconds(210))
     self.assertFalse(ts2 in ts1)
示例#15
0
 def test_span_duration_less_than_frequency(self):
     arr = np.arange(10)
     freq = Seconds(1)
     duration = Milliseconds(500)
     ts = ArrayWithUnits(arr, [TimeDimension(freq, duration)])
     self.assertEqual(TimeSlice(Milliseconds(9500)), ts.dimensions[0].span)
示例#16
0
 def test_can_index_2d_time_series_with_single_integer_index(self):
     arr = np.random.random_sample((10, 3))
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq), IdentityDimension()])
     ts2 = ts[5]
     self.assertEqual((3, ), ts2.shape)
示例#17
0
 def test_duration_in_seconds_two_seconds(self):
     arr = np.arange(10)
     freq = Seconds(2)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     self.assertEqual(2, ts.dimensions[0].duration_in_seconds)
示例#18
0
 def test_get_index_error_when_using_out_of_range_int_index(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     self.assertRaises(IndexError, lambda: ts[100])
示例#19
0
 def test_concatenation_with_differing_freqs_and_durations_raises(self):
     ts = ArrayWithUnits(np.arange(10),
                         [TimeDimension(Seconds(1), Seconds(2))])
     ts2 = ArrayWithUnits(np.arange(10, 20),
                          [TimeDimension(Seconds(1), Seconds(1))])
     self.assertRaises(ValueError, lambda: ts.concatenate(ts2))
示例#20
0
 def test_different_units_equal(self):
     self.assertEqual(Seconds(1), Milliseconds(1000))
示例#21
0
 def test_can_instantiate_time_slice_instance_without_start_argument(self):
     duration = Seconds(100)
     ts = TimeSlice(duration)
     self.assertEqual(duration, ts.duration)
     self.assertEqual(Seconds(0), ts.start)
示例#22
0
 def test_equivalent_timeslices_hash_to_the_same_value(self):
     ts1 = TimeSlice(start=Seconds(1), duration=Seconds(7))
     ts2 = TimeSlice(start=Milliseconds(1000), duration=Milliseconds(7000))
     self.assertEqual(hash(ts1), hash(ts2))
示例#23
0
 def test_can_find_null_intersection(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(100))
     ts2 = TimeSlice(Seconds(100), start=Seconds(200))
     intersection = ts1 & ts2
     self.assertEqual(Seconds(0), intersection.duration)
示例#24
0
 def test_exactly_equal_timeslices_hash_to_the_same_value(self):
     ts1 = TimeSlice(start=Seconds(1), duration=Seconds(7))
     ts2 = TimeSlice(start=Seconds(1), duration=Seconds(7))
     self.assertEqual(hash(ts1), hash(ts2))
示例#25
0
 def test_does_not_contain_point_in_time_before(self):
     ts = TimeSlice(Seconds(100), start=Seconds(200))
     self.assertFalse(Seconds(10) in ts)
示例#26
0
 def test_span_freq_and_duration_equal(self):
     arr = np.arange(10)
     freq = Seconds(1)
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     self.assertEqual(TimeSlice(Seconds(10)), ts.dimensions[0].span)
示例#27
0
 def span(self):
     try:
         start = self._data.timeslice[0].start
         return TimeSlice(start=start, duration=self.end - start)
     except IndexError:
         return TimeSlice(duration=Seconds(0))
示例#28
0
 def test_different_timeslices_hash_to_different_values(self):
     ts1 = TimeSlice(start=Seconds(1), duration=Seconds(7))
     ts2 = TimeSlice(start=Seconds(1), duration=Seconds(8))
     self.assertNotEqual(hash(ts1), hash(ts2))
示例#29
0
 def __str__(self):
     f = self.frequency / Seconds(1)
     d = self.duration / Seconds(1)
     return '{self.__class__.__name__}(f={f}, d={d})'.format(**locals())
示例#30
0
 def test_contains_slice(self):
     ts1 = TimeSlice(Seconds(100), start=Seconds(200))
     ts2 = TimeSlice(Seconds(10), Seconds(250))
     self.assertTrue(ts2 in ts1)