Skip to content

Commit 0473aab

Browse files
TST: Close ZipFile in compression test (#22679)
* Updates HypothesisCheck setting * Skips tests for old xlrd
1 parent 857515f commit 0473aab

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

pandas/conftest.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
import pandas as pd
99
from pandas.compat import PY3
1010
import pandas.util._test_decorators as td
11-
1211
import hypothesis
13-
hypothesis.settings.suppress_health_check = (hypothesis.HealthCheck.too_slow,)
14-
# HealthCheck.all() to disable all health checks
15-
# https://hypothesis.readthedocs.io/en/latest/healthchecks.html
12+
13+
14+
hypothesis.settings.register_profile(
15+
"ci",
16+
suppress_health_check=(hypothesis.HealthCheck.too_slow,)
17+
)
18+
hypothesis.settings.load_profile("ci")
1619

1720

1821
def pytest_addoption(parser):

pandas/tests/io/test_excel.py

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def get_exceldf(self, basename, ext, *args, **kwds):
105105
class ReadingTestsBase(SharedItems):
106106
# This is based on ExcelWriterBase
107107

108+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
108109
def test_usecols_int(self, ext):
109110

110111
dfref = self.get_csv_refdf('test1')
@@ -122,6 +123,7 @@ def test_usecols_int(self, ext):
122123
tm.assert_frame_equal(df2, dfref, check_names=False)
123124
tm.assert_frame_equal(df3, dfref, check_names=False)
124125

126+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
125127
def test_usecols_list(self, ext):
126128

127129
dfref = self.get_csv_refdf('test1')
@@ -140,6 +142,7 @@ def test_usecols_list(self, ext):
140142
tm.assert_frame_equal(df2, dfref, check_names=False)
141143
tm.assert_frame_equal(df3, dfref, check_names=False)
142144

145+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
143146
def test_usecols_str(self, ext):
144147

145148
dfref = self.get_csv_refdf('test1')
@@ -219,6 +222,7 @@ def test_excel_passes_na(self, ext):
219222
columns=['Test'])
220223
tm.assert_frame_equal(parsed, expected)
221224

225+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
222226
def test_deprecated_sheetname(self, ext):
223227
# gh-17964
224228
excel = self.get_excelfile('test1', ext)
@@ -229,6 +233,7 @@ def test_deprecated_sheetname(self, ext):
229233
with pytest.raises(TypeError):
230234
read_excel(excel, sheet='Sheet1')
231235

236+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
232237
def test_excel_table_sheet_by_index(self, ext):
233238

234239
excel = self.get_excelfile('test1', ext)
@@ -507,6 +512,7 @@ def test_date_conversion_overflow(self, ext):
507512
result = self.get_exceldf('testdateoverflow', ext)
508513
tm.assert_frame_equal(result, expected)
509514

515+
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
510516
def test_sheet_name_and_sheetname(self, ext):
511517
# GH10559: Minor improvement: Change "sheet_name" to "sheetname"
512518
# GH10969: DOC: Consistent var names (sheetname vs sheet_name)

pandas/tests/io/test_pickle.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ def compress_file(self, src_path, dest_path, compression):
332332
f = bz2.BZ2File(dest_path, "w")
333333
elif compression == 'zip':
334334
import zipfile
335-
zip_file = zipfile.ZipFile(dest_path, "w",
336-
compression=zipfile.ZIP_DEFLATED)
337-
zip_file.write(src_path, os.path.basename(src_path))
335+
f = zipfile.ZipFile(dest_path, "w",
336+
compression=zipfile.ZIP_DEFLATED)
337+
f.write(src_path, os.path.basename(src_path))
338338
elif compression == 'xz':
339339
lzma = pandas.compat.import_lzma()
340340
f = lzma.LZMAFile(dest_path, "w")
@@ -345,7 +345,7 @@ def compress_file(self, src_path, dest_path, compression):
345345
if compression != "zip":
346346
with open(src_path, "rb") as fh:
347347
f.write(fh.read())
348-
f.close()
348+
f.close()
349349

350350
def test_write_explicit(self, compression, get_random_path):
351351
base = get_random_path

pandas/util/testing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ class for all warnings. To check that no warning is returned,
25602560
the ``__warningsregistry__`` to ensure that no warning messages are
25612561
suppressed by this context manager. If ``None`` is specified,
25622562
the ``__warningsregistry__`` keeps track of which warnings have been
2563-
shown, and does not show them again.
2563+
shown, and does not show them again.
25642564
check_stacklevel : bool, default True
25652565
If True, displays the line that called the function containing
25662566
the warning to show were the function is called. Otherwise, the
@@ -2589,7 +2589,7 @@ class for all warnings. To check that no warning is returned,
25892589
with warnings.catch_warnings(record=True) as w:
25902590

25912591
if clear is not None:
2592-
# make sure that we are clearning these warnings
2592+
# make sure that we are clearing these warnings
25932593
# if they have happened before
25942594
# to guarantee that we will catch them
25952595
if not is_list_like(clear):

0 commit comments

Comments
 (0)