Skip to content

Commit 38aefad

Browse files
author
jnecus
committed
use ensure_clean rather than explicit os.remove pandas-dev#34384
I have made a start at this issue pandas-dev#34384. Please let me know if I am along the right lines (beginner contributor). I've left a space in code_checks.sh where I expect to implement the check for instances of 'os.remove' throughout the code.
1 parent abff45c commit 38aefad

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

ci/code_checks.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ if mods:
266266
sys.exit(len(mods))
267267
"
268268
RET=$(($RET + $?)) ; echo $MSG "DONE"
269-
269+
270+
MSG='Check code for instances of os.remove' ; echo $MSG
271+
#TODO: insert check here Issue #34384
272+
RET=$(($RET + $?)) ; echo $MSG "DONE"
273+
274+
270275
fi
271276

272277
### DOCTESTS ###

pandas/tests/io/excel/test_openpyxl.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas._testing as tm
99

1010
from pandas.io.excel import ExcelWriter, _OpenpyxlWriter
11+
from pandas.testing import ensure_clean
1112

1213
openpyxl = pytest.importorskip("openpyxl")
1314

@@ -120,4 +121,4 @@ def test_to_excel_with_openpyxl_engine(ext, tmpdir):
120121
styled.to_excel(filename, engine="openpyxl")
121122

122123
assert filename.exists()
123-
os.remove(filename)
124+
ensure_clean(filename)

pandas/tests/io/excel/test_writers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def test_to_excel_unicode_filename(self, ext, path):
901901
# assert 1 == cell_xf.border.bottom_line_style
902902
# assert 1 == cell_xf.border.left_line_style
903903
# assert 2 == cell_xf.alignment.hor_align
904-
# os.remove(filename)
904+
# ensure_clean(filename)
905905
# def test_to_excel_header_styling_xlsx(self, engine, ext):
906906
# import StringIO
907907
# s = StringIO(
@@ -953,7 +953,7 @@ def test_to_excel_unicode_filename(self, ext, path):
953953
# mergedcells_addrs = ["C1", "E1", "G1"]
954954
# for maddr in mergedcells_addrs:
955955
# assert ws.cell(maddr).merged
956-
# os.remove(filename)
956+
# ensure_clean(filename)
957957

958958
@pytest.mark.parametrize("use_headers", [True, False])
959959
@pytest.mark.parametrize("r_idx_nlevels", [1, 2, 3])

pandas/tests/io/pytables/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pandas.io.pytables import HDFStore
8+
from pandas.testing import ensure_clean
89

910
tables = pytest.importorskip("tables")
1011
# set these parameters so we don't have file sharing
@@ -16,7 +17,7 @@
1617
def safe_remove(path):
1718
if path is not None:
1819
try:
19-
os.remove(path)
20+
ensure_clean(path)
2021
except OSError:
2122
pass
2223

0 commit comments

Comments
 (0)