Permalink
Browse files

BUG la.cov() overwrites input array; closes #62

  • Loading branch information...
1 parent 2a6971f commit 709954369a4ce27853c0331b89cd383aab950671 @kwgoodman committed Jul 5, 2012
Showing with 20 additions and 32 deletions.
  1. +2 −2 README.rst
  2. +1 −0 RELEASE.rst
  3. +1 −0 la/farray/misc.py
  4. +16 −30 la/farray/tests/farray_test.py
View
@@ -122,9 +122,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la
>>> la.test()
<snip>
- Ran 3018 tests in 9.225s
+ Ran 3020 tests in 9.225s
OK
- <nose.result.TextTestResult run=3018 errors=0 failures=0>
+ <nose.result.TextTestResult run=3020 errors=0 failures=0>
The ``la`` package contains C extensions that speed up common alignment
operations such as adding two unaligned larrys. If the C extensions don't
View
@@ -35,6 +35,7 @@ la 0.7
**Bug fixes**
- #59 Proper int promotion in larry.cumsum() and larry.cumprod()
+- #62 la.cov() overwrites NaNs in input array
Older versions
==============
View
@@ -144,6 +144,7 @@ def covMissing(R):
demeaned and the covariance is normalized by T not T-1.
"""
+ R = R.copy()
mask = np.isnan(R)
np.putmask(R, mask, 0)
mask = np.asarray(mask, np.float64)
@@ -13,7 +13,8 @@
from la.util.testing import printfail
from la.farray import group_ranking, group_mean, group_median
from la.farray import (movingsum, movingrank, movingsum_forward, ranking,
- geometric_mean, unique_group, correlation, lastrank)
+ geometric_mean, unique_group, correlation, lastrank,
+ covMissing)
# Sector functions ----------------------------------------------------------
@@ -731,32 +732,17 @@ def test_lastrank_3(self):
s = lastrank(np.array([]))
aae(s, np.nan, err_msg="size 0 lastrank fail")
-# Unit tests ----------------------------------------------------------------
-
-def suite():
-
- unit = unittest.TestLoader().loadTestsFromTestCase
- s = []
-
- # Sector functions
- s.append(unit(Test_group_ranking))
- s.append(unit(Test_group_mean))
- s.append(unit(Test_group_median))
-
- # Normalize functions
- s.append(unit(Test_ranking))
- s.append(unit(Test_geometric_mean))
- s.append(unit(Test_movingsum))
- s.append(unit(Test_movingsum_forward))
- s.append(unit(Test_movingrank))
- s.append(unit(Test_lastrank))
-
- # Calc function
- s.append(unit(Test_correlation))
-
- return unittest.TestSuite(s)
-
-def run():
- suite = testsuite()
- unittest.TextTestRunner(verbosity=2).run(suite)
-
+def test_covMissing_1():
+ "farray.covMissing_1"
+ a = np.ones((2,10))
+ actual = covMissing(a)
+ desired = np.ones((2,2))
+ aae(actual, desired)
+
+def test_covMissing_2():
+ "farray.covMissing_2"
+ a = np.ones((2,4))
+ a[0,1] = np.nan
+ b = a.copy()
+ ignore = covMissing(a)
+ aae(a, b)

0 comments on commit 7099543

Please sign in to comment.