Skip to content

Commit 6528209

Browse files
committed
remove deprecated use of StopIteration in generator
catch some more FutureWarnings
1 parent 793c770 commit 6528209

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

pandas/core/groupby.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ def is_in_obj(gpr):
24662466
"Defaulting to column but "
24672467
"this will raise an ambiguity error in a "
24682468
"future version") % gpr,
2469-
FutureWarning, stacklevel=3)
2469+
FutureWarning, stacklevel=5)
24702470
in_axis, name, gpr = True, gpr, obj[gpr]
24712471
exclusions.append(name)
24722472
elif gpr in obj.index.names:
@@ -4025,7 +4025,9 @@ def __iter__(self):
40254025
sdata = self._get_sorted_data()
40264026

40274027
if self.ngroups == 0:
4028-
raise StopIteration
4028+
# we are inside a generator, rather than raise StopIteration
4029+
# we merely return signal the end
4030+
return
40294031

40304032
starts, ends = lib.generate_slices(self.slabels, self.ngroups)
40314033

pandas/io/stata.py

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def read_stata(filepath_or_buffer, convert_dates=True,
175175
reader.close()
176176
return data
177177

178+
178179
_date_formats = ["%tc", "%tC", "%td", "%d", "%tw", "%tm", "%tq", "%th", "%ty"]
179180

180181

pandas/tools/tests/test_pivot.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,26 @@ def _check_output(result, values_col, index=['A', 'B'],
381381
df = df.set_index(['JOB', 'NAME', 'YEAR', 'MONTH'], drop=False,
382382
append=False)
383383

384-
result = df.pivot_table(index=['JOB', 'NAME'],
385-
columns=['YEAR', 'MONTH'],
386-
values=['DAYS', 'SALARY'],
387-
aggfunc={'DAYS': 'mean', 'SALARY': 'sum'},
388-
margins=True)
389-
390-
expected = df.pivot_table(index=['JOB', 'NAME'],
391-
columns=['YEAR', 'MONTH'], values=['DAYS'],
392-
aggfunc='mean', margins=True)
384+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
385+
result = df.pivot_table(index=['JOB', 'NAME'],
386+
columns=['YEAR', 'MONTH'],
387+
values=['DAYS', 'SALARY'],
388+
aggfunc={'DAYS': 'mean', 'SALARY': 'sum'},
389+
margins=True)
390+
391+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
392+
expected = df.pivot_table(index=['JOB', 'NAME'],
393+
columns=['YEAR', 'MONTH'],
394+
values=['DAYS'],
395+
aggfunc='mean', margins=True)
393396

394397
tm.assert_frame_equal(result['DAYS'], expected['DAYS'])
395398

396-
expected = df.pivot_table(index=['JOB', 'NAME'],
397-
columns=['YEAR', 'MONTH'], values=['SALARY'],
398-
aggfunc='sum', margins=True)
399+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
400+
expected = df.pivot_table(index=['JOB', 'NAME'],
401+
columns=['YEAR', 'MONTH'],
402+
values=['SALARY'],
403+
aggfunc='sum', margins=True)
399404

400405
tm.assert_frame_equal(result['SALARY'], expected['SALARY'])
401406

0 commit comments

Comments
 (0)