Permalink
Browse files

BUG Proper int promotion in cumsum and cumprod.

Closes #59. All unit tests now pass.
  • Loading branch information...
1 parent b5612de commit d37aad3a4ecc07a800c05160ffc6e2601356ac58 @kwgoodman committed Apr 29, 2012
Showing with 28 additions and 8 deletions.
  1. +6 −2 RELEASE.rst
  2. +2 −2 la/deflarry.py
  3. +20 −4 la/tests/deflarry_unary_test.py
View
@@ -26,6 +26,10 @@ la 0.7
- Numpy array version of move_median() removed since bottleneck now used
+**Bug fixes**
+
+- #59 Proper int promotion in larry.cumsum() and larry.cumprod()
+
Older versions
==============
@@ -64,7 +68,7 @@ la 0.6
- optional parameter for larry creation renamed from integrity to validate
-**Bugs fixes**
+**Bug fixes**
- #14 larry.lag() gives wrong output when nlag=0
- #20 Indexing chokes on lar[:,3:2]
@@ -118,7 +122,7 @@ Bottleneck package (http://pypi.python.org/pypi/Bottleneck).
- movingsum and movingrank have been deprecated and will be removed in la 0.6;
use move_sum and move_ranking instead
-**Bugs fixes**
+**Bug fixes**
- Please report bugs at https://github.com/kwgoodman/la/issues
- #1 Due to a typo, la.info() crashed if h5py could not be imported
View
@@ -348,7 +348,7 @@ def cumsum(self, axis):
y = self.copy()
idx = np.isnan(y.x)
np.putmask(y.x, idx, 0)
- y.x.cumsum(axis, out=y.x)
+ y.x = y.x.cumsum(axis)
if idx.any():
np.putmask(y.x, idx, np.nan)
return y
@@ -414,7 +414,7 @@ def cumprod(self, axis):
y = self.copy()
idx = np.isnan(y.x)
np.putmask(y.x, idx, 1)
- y.x.cumprod(axis, out=y.x)
+ y.x = y.x.cumprod(axis)
if idx.any():
np.putmask(y.x, idx, np.nan)
return y
@@ -77,12 +77,28 @@ def test___pow__():
yield unit_maker, "__pow__", np.power, {'la':[1.3], 'np':[1.3]}
def test_cumsum():
- yield unit_maker, "cumsum", np.cumsum, {'la':[0], 'np':[0]}
- yield unit_maker, "cumsum", np.cumsum, {'la':[-1], 'np':[-1]}
+ def cumsum(a, axis):
+ m = np.ma.fix_invalid(a)
+ m = m.cumsum(axis)
+ mask = m.mask
+ a = np.asarray(m)
+ if mask.any():
+ a[mask] = np.nan
+ return a
+ yield unit_maker, "cumsum", cumsum, {'la':[0], 'np':[0]}
+ yield unit_maker, "cumsum", cumsum, {'la':[-1], 'np':[-1]}
def test_cumprod():
- yield unit_maker, "cumprod", np.cumprod, {'la':[0], 'np':[0]}
- yield unit_maker, "cumprod", np.cumprod, {'la':[-1], 'np':[-1]}
+ def cumprod(a, axis):
+ m = np.ma.fix_invalid(a)
+ m = m.cumprod(axis)
+ mask = m.mask
+ a = np.asarray(m)
+ if mask.any():
+ a[mask] = np.nan
+ return a
+ yield unit_maker, "cumprod", cumprod, {'la':[0], 'np':[0]}
+ yield unit_maker, "cumprod", cumprod, {'la':[-1], 'np':[-1]}
def test_clip():
yield unit_maker, "clip", np.clip, {'la':[-1,1], 'np':[-1,1]}

0 comments on commit d37aad3

Please sign in to comment.