Skip to content

Commit

Permalink
BF: Product and variance would change TimeArray units.
Browse files Browse the repository at this point in the history
We raise an error instead of doing that.
  • Loading branch information
arokem committed Jun 19, 2012
1 parent 39fd0a8 commit dcd6bc2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions nitime/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def test_TimeArray_math():
tnew = timeunits + range(10)
npt.assert_equal(tnew, timeunits+time1) # recall that time1 was 0-10ms



def test_TimeArray_comparison():
"Comparison with unitless quantities should convert to TimeArray units"
time = ts.TimeArray(range(10), time_unit='ms')
Expand Down Expand Up @@ -901,3 +903,11 @@ def test_timearray_math_functions():
# comparison with unitless should convert to the TimeArray's units
assert getattr(b, f)() == getattr(a,f)()

def test_timearray_var_prod():
"""
Variance and product change the TimeArray units, so they are not
implemented and raise an error
"""
a = ts.TimeArray(range(10))
npt.assert_raises(NotImplementedError, a.var)
npt.assert_raises(NotImplementedError, a.prod)
17 changes: 12 additions & 5 deletions nitime/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def __ge__(self,val):
def __eq__(self,val):
val = self._convert_if_needed(val)
return np.ndarray.__eq__(self,val)

def min(self, *args,**kwargs):
ret = TimeArray(np.ndarray.min(self, *args,**kwargs),
time_unit=base_unit)
Expand Down Expand Up @@ -299,12 +299,17 @@ def sum(self, *args,**kwargs):
time_unit=base_unit)
ret.convert_unit(self.time_unit)
return ret


def prod(self, *args, **kwargs):
e_s = "Product computation changes TimeArray units"
raise NotImplementedError(e_s)


def var(self, *args, **kwargs):
tmp = np.array(self, np.float) / self._conversion_factor
ret = TimeArray(tmp.var(*args,**kwargs), time_unit=self.time_unit)
return ret
e_s = "Variance computation changes TimeArray units"
raise NotImplementedError(e_s)


def std(self, *args, **kwargs):
"""Returns the standard deviation of this TimeArray (with time units)
Expand All @@ -314,6 +319,8 @@ def std(self, *args, **kwargs):
time_unit=base_unit)
ret.convert_unit(self.time_unit)
return ret


def index_at(self, t, tol=None, mode='closest'):
""" Returns the integer indices that corresponds to the time t
Expand Down

0 comments on commit dcd6bc2

Please sign in to comment.