Skip to content

Commit df79c64

Browse files
author
jnecus
committed
use ensure_clean rather than explicit os.remove pandas-dev#34384
1 parent 38aefad commit df79c64

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

ci/code_checks.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,11 @@ if mods:
266266
sys.exit(len(mods))
267267
"
268268
RET=$(($RET + $?)) ; echo $MSG "DONE"
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-
269+
270+
MSG='Check code for instances of os.remove' ; echo $MSG
271+
invgrep -R --include="*.py*" -E "os.remove" pandas
272+
RET=$(($RET + $?)) ; echo $MSG "DONE"
273+
275274
fi
276275

277276
### DOCTESTS ###

pandas/tests/io/excel/test_openpyxl.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pandas._testing as tm
99

1010
from pandas.io.excel import ExcelWriter, _OpenpyxlWriter
11-
from pandas.testing import ensure_clean
11+
from pandas._testing import ensure_clean
1212

1313
openpyxl = pytest.importorskip("openpyxl")
1414

@@ -109,16 +109,17 @@ def test_write_append_mode(ext, mode, expected):
109109

110110

111111
def test_to_excel_with_openpyxl_engine(ext, tmpdir):
112-
# GH 29854
113-
df1 = DataFrame({"A": np.linspace(1, 10, 10)})
114-
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
115-
df = pd.concat([df1, df2], axis=1)
116-
styled = df.style.applymap(
117-
lambda val: "color: %s" % ("red" if val < 0 else "black")
118-
).highlight_max()
119-
120-
filename = tmpdir / "styled.xlsx"
121-
styled.to_excel(filename, engine="openpyxl")
122-
123-
assert filename.exists()
124-
ensure_clean(filename)
112+
113+
with ensure_clean('styled.xlsx') as filename:
114+
# GH 29854
115+
df1 = DataFrame({"A": np.linspace(1, 10, 10)})
116+
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
117+
df = pd.concat([df1, df2], axis=1)
118+
styled = df.style.applymap(
119+
lambda val: "color: %s" % ("red" if val < 0 else "black")
120+
).highlight_max()
121+
122+
styled.to_excel(filename, engine="openpyxl")
123+
124+
assert filename.exists()
125+

pandas/tests/io/pytables/common.py

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

77
from pandas.io.pytables import HDFStore
8-
from pandas.testing import ensure_clean
8+
from pandas._testing import ensure_clean
99

1010
tables = pytest.importorskip("tables")
1111
# set these parameters so we don't have file sharing
@@ -17,7 +17,8 @@
1717
def safe_remove(path):
1818
if path is not None:
1919
try:
20-
ensure_clean(path)
20+
with ensure_clean(path) as filename:
21+
ensure_clean(filename)
2122
except OSError:
2223
pass
2324

0 commit comments

Comments
 (0)