Skip to content

Commit 6203957

Browse files
committed
BUG: return NA in all-NA case in Series.corr instead of raising exception, GH #548
1 parent 59a09a9 commit 6203957

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

RELEASE.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pandas 0.6.2
3636
prevent accidentally modifying the data source (GH #316)
3737
- Refactor to remove deprecated ``LongPanel`` class (PR #552)
3838
- Deprecated ``Panel.to_long``, renamed to ``to_frame``
39-
- Added ``DataFrame.to_panel`` with code adapted from ``LongPanel.to_long``
4039

4140
**New features / modules**
4241

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

5252
**Improvements to existing features**
5353

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

103104
Thanks
104105
------
105106
- Craig Austin
106-
- Andreas Hilboll
107-
- Matt Harrison
108107
- Mario Gamboa-Cavazos
109108
- Arthur Gerigk
109+
- Matt Harrison
110+
- Andreas Hilboll
110111
- Adam Klein
111112
- Gregg Lind
112113
- Solomon Negusse
@@ -115,6 +116,7 @@ Thanks
115116
- Sam Reckoner
116117
- Craig Reeson
117118
- Jan Schulz
119+
- Ted Square
118120
- Dieter Vandenbussche
119121

120122
pandas 0.6.1

pandas/core/nanops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,15 @@ def nancorr(a, b, method='pearson'):
230230
a, b: ndarrays
231231
"""
232232
assert(len(a) == len(b))
233-
if len(a) == 0:
234-
return np.nan
235233

236234
valid = notnull(a) & notnull(b)
237235
if not valid.all():
238236
a = a[valid]
239237
b = b[valid]
240238

239+
if len(a) == 0:
240+
return np.nan
241+
241242
f = get_corr_func(method)
242243
return f(a, b)
243244

pandas/tests/test_series.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,11 @@ def test_corr(self):
981981
# No overlap
982982
self.assert_(np.isnan(self.ts[::2].corr(self.ts[1::2])))
983983

984+
# all NA
985+
cp = self.ts[:10].copy()
986+
cp[:] = np.nan
987+
self.assert_(isnull(cp.corr(cp)))
988+
984989
A = tm.makeTimeSeries()
985990
B = tm.makeTimeSeries()
986991
result = A.corr(B)

0 commit comments

Comments
 (0)