pydata/pandas — pull request #1650 by todddeluca (2012-07-19 21:10:41+00:00)
Title: Series.describe() fails for empty and None series.

Running `describe()` raises and exception for `Series([])` and `Series([None])`. See the following examples:

In [416]: Series([]).describe()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 Series([]).describe()

/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0rc2-py2.7-macosx-10.4-x86_64.egg/pandas/core/series.pyc in describe(self, percentile_width)
1363 'max']
1364
-> 1365 data = [self.count(), self.mean(), self.std(), self.min(),
1366 self.quantile(lb), self.median(), self.quantile(ub),
1367 self.max()]

/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0rc2-py2.7-macosx-10.4-x86_64.egg/pandas/core/series.pyc in min(self, axis, out, skipna, level)
1067 if level is not None:
1068 return self._agg_by_level('min', level=level, skipna=skipna)
-> 1069 return nanops.nanmin(self.values, skipna=skipna)
1070
1071 @Substitution(name='maximum', shortname='max',

/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0rc2-py2.7-macosx-10.4-x86_64.egg/pandas/core/nanops.pyc in f(values, axis, skipna, **kwds)
41 result = alt(values, axis=axis, skipna=skipna, **kwds)
42 except Exception:
---> 43 result = alt(values, axis=axis, skipna=skipna, **kwds)
44
45 return result

/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0rc2-py2.7-macosx-10.4-x86_64.egg/pandas/core/nanops.pyc in _nanmin(values, axis, skipna)
152 result = __builtin__.min(values)
153 else:
--> 154 result = values.min(axis)
155
156 return _maybe_null_out(result, axis, mask)

ValueError: zero-size array to minimum.reduce without identity

In [388]: s = pandas.Series([None])

In [389]: s.describe()
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in ()
----> 1 s.describe()

/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0rc2-py2.7-macosx-10.4-x86_64.egg/pandas/core/series.pyc in describe(self, percentile_width)
1334
1335 objcounts = Counter(self.dropna().values)
-> 1336 top, freq = objcounts.most_common(1)[0]
1337 data = [self.count(), len(objcounts), top, freq]
1338

IndexError: list index out of range

In [395]: s = pandas.Series([np.nan, np.nan])

In [396]: s.describe()
Out[396]:
count 0
mean NaN
std NaN
min NaN
25% NaN
50% NaN
75% NaN
max NaN

I have included `Series([np.nan])` because its output is affected by the pull request.

After the pull request the output is as follows:

In [3]: Series([]).describe()
Out[3]: count 0

In [4]: Series([None]).describe()
Out[4]:
count 0
unique 0

In [5]: Series([np.nan]).describe()
Out[5]: count 0

The pull request fixes the `ValueError` from the call to `values.min(axis)` and the `IndexError` from accessing `most_common(1)[0]` by only returning a small amount of count data when the Series object is empty or contains all NaN or None values. Is this the right approach? It changes the output for Series objects with all NaN values.

Test coverage was written but I couldn't figure out how to run the tests. Any hints?

Regards,
Todd