Skip to content

Commit

Permalink
BUG: return NA in all-NA case in Series.corr instead of raising excep…
Browse files Browse the repository at this point in the history
…tion, GH #548
  • Loading branch information
wesm committed Dec 28, 2011
1 parent 59a09a9 commit 6203957
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pandas 0.6.2
prevent accidentally modifying the data source (GH #316)
- Refactor to remove deprecated ``LongPanel`` class (PR #552)
- Deprecated ``Panel.to_long``, renamed to ``to_frame``
- Added ``DataFrame.to_panel`` with code adapted from ``LongPanel.to_long``

**New features / modules**

Expand All @@ -47,7 +46,8 @@ pandas 0.6.2
- Add dict-like ``get`` function to DataFrame and Panel (PR #521)
- DataFrame.iterrows method for efficiently iterating through the rows of a
DataFrame
- A
- Added ``DataFrame.to_panel`` with code adapted from ``LongPanel.to_long``
- ``reindex_axis`` method added to DataFrame

**Improvements to existing features**

Expand Down Expand Up @@ -99,14 +99,15 @@ pandas 0.6.2
- Fix type inference logic with boolean lists and arrays in DataFrame indexing
- Use centered sum of squares in R-square computation if entity_effects=True
in panel regression
- Handle all NA case in Series.corr, was raising exception (GH #548)

Thanks
------
- Craig Austin
- Andreas Hilboll
- Matt Harrison
- Mario Gamboa-Cavazos
- Arthur Gerigk
- Matt Harrison
- Andreas Hilboll
- Adam Klein
- Gregg Lind
- Solomon Negusse
Expand All @@ -115,6 +116,7 @@ Thanks
- Sam Reckoner
- Craig Reeson
- Jan Schulz
- Ted Square
- Dieter Vandenbussche

pandas 0.6.1
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ def nancorr(a, b, method='pearson'):
a, b: ndarrays
"""
assert(len(a) == len(b))
if len(a) == 0:
return np.nan

valid = notnull(a) & notnull(b)
if not valid.all():
a = a[valid]
b = b[valid]

if len(a) == 0:
return np.nan

f = get_corr_func(method)
return f(a, b)

Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,11 @@ def test_corr(self):
# No overlap
self.assert_(np.isnan(self.ts[::2].corr(self.ts[1::2])))

# all NA
cp = self.ts[:10].copy()
cp[:] = np.nan
self.assert_(isnull(cp.corr(cp)))

A = tm.makeTimeSeries()
B = tm.makeTimeSeries()
result = A.corr(B)
Expand Down

0 comments on commit 6203957

Please sign in to comment.