Skip to content

Commit

Permalink
Merge branch 'PR3510'
Browse files Browse the repository at this point in the history
* PR3510:
  Fixed Unbound Variable `edge` access when BinGrouper is empty
  • Loading branch information
y-p committed May 3, 2013
2 parents ee4a740 + b30c37a commit 99137af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pandas 0.11.1
- applymap on a DataFrame with a non-unique index now works
(removed warning) (GH2786_), and fix (GH3230_)
- Fix to_csv to handle non-unique columns (GH3495_)
- Fixed bug in groupby with empty series referencing a variable before assignment. (GH3510_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand All @@ -83,6 +84,7 @@ pandas 0.11.1
.. _GH3426: https://github.com/pydata/pandas/issues/3426
.. _GH3466: https://github.com/pydata/pandas/issues/3466
.. _GH3038: https://github.com/pydata/pandas/issues/3038
.. _GH3510: https://github.com/pydata/pandas/issues/3510
.. _GH3437: https://github.com/pydata/pandas/issues/3437
.. _GH3455: https://github.com/pydata/pandas/issues/3455
.. _GH3457: https://github.com/pydata/pandas/issues/3457
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,8 @@ def get_iterator(self, data, axis=0):
yield label, data[start:edge]
start = edge

if edge < len(data):
yield self.binlabels[-1], data[edge:]
if start < len(data):
yield self.binlabels[-1], data[start:]
else:
start = 0
for edge, label in izip(self.bins, self.binlabels):
Expand All @@ -1022,8 +1022,8 @@ def get_iterator(self, data, axis=0):
start = edge

n = len(data.axes[axis])
if edge < n:
inds = range(edge, n)
if start < n:
inds = range(start, n)
yield self.binlabels[-1], data.take(inds, axis=axis)

def apply(self, f, data, axis=0, keep_internal=False):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,16 @@ def noddy(value, weight):
# don't die
no_toes = df_grouped.apply(lambda x: noddy(x.value, x.weight ))

def test_groupby_with_empty(self):
import pandas as pd
index = pd.DatetimeIndex(())
data = ()
series = pd.Series(data, index)
grouper = pd.tseries.resample.TimeGrouper('D')
grouped = series.groupby(grouper)
assert next(iter(grouped), None) is None


def assert_fp_equal(a, b):
assert((np.abs(a - b) < 1e-12).all())

Expand Down

0 comments on commit 99137af

Please sign in to comment.