[Scipy-svn] r3033 - trunk/Lib/sandbox/timeseries
scipy-svn at scipy.org
scipy-svn at scipy.org
Tue May 22 16:19:56 EDT 2007
Author: mattknox_ca
Date: 2007-05-22 15:19:52 -0500 (Tue, 22 May 2007)
New Revision: 3033
Modified:
trunk/Lib/sandbox/timeseries/tseries.py
Log:
operations on incompatible TimeSeries objects now returns a plain MaskedArray instead of raising an error. Compatible TimeSeries still return a TimeSeries object.
Modified: trunk/Lib/sandbox/timeseries/tseries.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tseries.py 2007-05-22 18:19:32 UTC (rev 3032)
+++ trunk/Lib/sandbox/timeseries/tseries.py 2007-05-22 20:19:52 UTC (rev 3033)
@@ -122,24 +122,36 @@
TimeSeriesError.__init__(self, msg)
#def _compatibilitycheck(a, b):
-def _timeseriescompat(a, b):
+def _timeseriescompat(a, b, raise_error=True):
"""Checks the date compatibility of two TimeSeries object.
Returns True if everything's fine, or raises an exception."""
if not (hasattr(a,'freq') and hasattr(b, 'freq')):
return True
if a.freq != b.freq:
- raise TimeSeriesCompatibilityError('freq', a.freq, b.freq)
+ if raise_error:
+ raise TimeSeriesCompatibilityError('freq', a.freq, b.freq)
+ else:
+ return False
elif a.start_date != b.start_date:
- raise TimeSeriesCompatibilityError('start_date',
- a.start_date, b.start_date)
+ if raise_error:
+ raise TimeSeriesCompatibilityError('start_date',
+ a.start_date, b.start_date)
+ else:
+ return False
else:
step_diff = a._dates.get_steps() != b._dates.get_steps()
if (step_diff is True) or (hasattr(step_diff, "any") and step_diff.any()):
- raise TimeSeriesCompatibilityError('time_steps',
- a._dates.get_steps(), b._dates.get_steps())
+ if raise_error:
+ raise TimeSeriesCompatibilityError('time_steps',
+ a._dates.get_steps(), b._dates.get_steps())
+ else:
+ return False
elif a.shape != b.shape:
- raise TimeSeriesCompatibilityError('size', "1: %s" % str(a.shape),
- "2: %s" % str(b.shape))
+ if raise_error:
+ raise TimeSeriesCompatibilityError('size', "1: %s" % str(a.shape),
+ "2: %s" % str(b.shape))
+ else:
+ return False
return True
@@ -234,10 +246,16 @@
"Execute the call behavior."
instance = self.obj
if isinstance(other, TimeSeries):
- assert(_timeseriescompat(instance, other))
+ compat = _timeseriescompat(instance, other, raise_error=False)
+ else:
+ compat = True
+
func = getattr(super(TimeSeries, instance), self._name)
- result = func(other, *args).view(type(instance))
- result._dates = instance._dates
+ if compat:
+ result = func(other, *args).view(type(instance))
+ result._dates = instance._dates
+ else:
+ result = func(other, *args)._series
return result
class _tsarraymethod(object):
More information about the Scipy-svn
mailing list