Skip to content

Commit 78ba15f

Browse files
committed
BLD: Clean up py36 build
Author: Jeff Reback <[email protected]> Closes #14979 from jreback/build_36 and squashes the following commits: 21f58d6 [Jeff Reback] resource closed warning in parsers 6528209 [Jeff Reback] remove deprecated use of StopIteration in generator catch some more FutureWarnings 793c770 [Jeff Reback] COMPAT: make sure to close state file handles on exception in reading c7f37fc [Jeff Reback] TST: remove some 3.6 warnings 2f7532c [Jeff Reback] BLD: add scipy to 3.6 build
1 parent d7e8f31 commit 78ba15f

File tree

9 files changed

+43
-26
lines changed

9 files changed

+43
-26
lines changed

ci/requirements-3.6.run

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
python-dateutil
22
pytz
33
numpy
4+
scipy

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=2)
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/parsers.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,20 @@ def _read(filepath_or_buffer, kwds):
385385
raise NotImplementedError("'nrows' and 'chunksize' cannot be used"
386386
" together yet.")
387387
elif nrows is not None:
388-
data = parser.read(nrows)
389-
parser.close()
388+
try:
389+
data = parser.read(nrows)
390+
finally:
391+
parser.close()
390392
return data
393+
391394
elif chunksize or iterator:
392395
return parser
393396

394-
data = parser.read()
395-
parser.close()
397+
try:
398+
data = parser.read()
399+
finally:
400+
parser.close()
401+
396402
return data
397403

398404
_parser_defaults = {

pandas/io/stata.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ def read_stata(filepath_or_buffer, convert_dates=True,
169169
if iterator or chunksize:
170170
data = reader
171171
else:
172-
data = reader.read()
173-
reader.close()
172+
try:
173+
data = reader.read()
174+
finally:
175+
reader.close()
174176
return data
175177

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

178181

pandas/io/tests/parser/test_unsupported.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def test_c_engine(self):
6969
msg = 'Error tokenizing data'
7070

7171
with tm.assertRaisesRegexp(ParserError, msg):
72-
read_table(StringIO(text), sep='\s+')
72+
read_table(StringIO(text), sep='\\s+')
7373
with tm.assertRaisesRegexp(ParserError, msg):
74-
read_table(StringIO(text), engine='c', sep='\s+')
74+
read_table(StringIO(text), engine='c', sep='\\s+')
7575

7676
msg = "Only length-1 thousands markers supported"
7777
data = """A|B|C

pandas/sparse/tests/test_array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def test_astype(self):
361361
arr.astype('i8')
362362

363363
arr = SparseArray([0, np.nan, 0, 1], fill_value=0)
364-
msg = 'Cannot convert non-finite values \(NA or inf\) to integer'
364+
msg = 'Cannot convert non-finite values \\(NA or inf\\) to integer'
365365
with tm.assertRaisesRegexp(ValueError, msg):
366366
arr.astype('i8')
367367

@@ -708,7 +708,7 @@ def test_cumsum(self):
708708
tm.assert_sp_array_equal(out, expected)
709709

710710
axis = 1 # SparseArray currently 1-D, so only axis = 0 is valid.
711-
msg = "axis\(={axis}\) out of bounds".format(axis=axis)
711+
msg = "axis\\(={axis}\\) out of bounds".format(axis=axis)
712712
with tm.assertRaisesRegexp(ValueError, msg):
713713
SparseArray(data).cumsum(axis=axis)
714714

pandas/tests/frame/test_dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def test_astype_cast_nan_inf_int(self):
390390
# GH14265, check nan and inf raise error when converting to int
391391
types = [np.int32, np.int64]
392392
values = [np.nan, np.inf]
393-
msg = 'Cannot convert non-finite values \(NA or inf\) to integer'
393+
msg = 'Cannot convert non-finite values \\(NA or inf\\) to integer'
394394

395395
for this_type in types:
396396
for this_val in values:

pandas/tests/series/test_dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_astype_cast_nan_inf_int(self):
4646
# GH14265, check nan and inf raise error when converting to int
4747
types = [np.int32, np.int64]
4848
values = [np.nan, np.inf]
49-
msg = 'Cannot convert non-finite values \(NA or inf\) to integer'
49+
msg = 'Cannot convert non-finite values \\(NA or inf\\) to integer'
5050

5151
for this_type in types:
5252
for this_val in values:

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)