Skip to content

use ensure_clean rather than explicit os.remove #34384 #34385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a4d6ae4
Update test_period_range.py
May 14, 2020
64de146
Update test_period_range.py
jnecus May 14, 2020
80e7f26
Update test_period_range.py
jnecus May 14, 2020
d4ac552
Update test_period_range.py
jnecus May 14, 2020
24365ab
Update test_period_range.py
May 14, 2020
6266771
Update test_period_range.py
May 14, 2020
e1ccaae
Update test_period_range.py
May 14, 2020
4df4bc7
Update test_period_range.py
jnecus May 14, 2020
abce52f
Update test_period_range.py
May 14, 2020
a0de23b
Update test_period_range.py
May 14, 2020
ae63191
Update test_period_range.py
May 14, 2020
054ade5
Update test_period_range.py
May 14, 2020
a40ab46
Update test_period_range.py
May 14, 2020
b749f8e
Update test_period_range.py
May 14, 2020
14e2c79
Update test_period_range.py
May 15, 2020
0d68e31
Merge remote-tracking branch 'upstream/master'
May 18, 2020
dce777b
Revert "Merge remote-tracking branch 'upstream/master'"
May 18, 2020
12ff5a5
Revert "Revert "Merge remote-tracking branch 'upstream/master'""
May 18, 2020
100d2ad
Merge remote-tracking branch 'upstream/master'
May 18, 2020
abff45c
Merge remote-tracking branch 'upstream/master'
May 26, 2020
38aefad
use ensure_clean rather than explicit os.remove #34384
May 26, 2020
df79c64
use ensure_clean rather than explicit os.remove #34384
May 26, 2020
ea16a0a
Merge remote-tracking branch 'upstream/master'
May 26, 2020
a6732f9
Update test_openpyxl.py
May 26, 2020
a931e2a
Merge remote-tracking branch 'upstream/master'
Jun 1, 2020
1db905a
removed safe_remove entirely
Jun 1, 2020
442d83c
Update test_openpyxl.py
Jun 1, 2020
dbb3d74
sorting imports
Jun 1, 2020
2799d13
Update test_openpyxl.py
Jun 1, 2020
3bef5f4
replace safe_remove with ensure clean
Jun 1, 2020
bb79fa3
Update test_openpyxl.py
Jun 1, 2020
6c3108e
Update common.py
Jun 1, 2020
3f2af9d
linting correction, excluding os.remove in common.py
Jun 2, 2020
6cc69f0
linting
Jun 2, 2020
02eeab1
Update test_openpyxl.py
Jun 2, 2020
3da1b95
Merge remote-tracking branch 'upstream/master'
Aug 12, 2020
2fb17a3
Update code_checks.sh
Aug 12, 2020
4034fd6
Update code_checks.sh
jnecus Aug 12, 2020
af8b575
Update test_store.py
jnecus Oct 2, 2020
7a3011e
updated ensure_clean as context manager
jnecus Oct 5, 2020
ee95e71
Update test_store.py
jnecus Oct 5, 2020
7791b7d
Update test_store.py
jnecus Oct 5, 2020
045d797
Update test_store.py
jnecus Oct 6, 2020
72ec987
Update test_store.py
jnecus Oct 6, 2020
f812a39
Update test_store.py
jnecus Oct 6, 2020
6575419
Update test_store.py
jnecus Oct 6, 2020
22258de
Update test_store.py
jnecus Oct 6, 2020
3e41dc5
Update test_store.py
jnecus Oct 7, 2020
b3e8d96
added safe_remove
jnecus Oct 7, 2020
2063623
test_context exception
jnecus Oct 8, 2020
9de691c
Update test_store.py
jnecus Oct 8, 2020
de874af
Update test_store.py
jnecus Oct 8, 2020
3309222
Update test_store.py
jnecus Oct 8, 2020
4c8091c
Update test_store.py
jnecus Oct 8, 2020
9474ebc
Update test_store.py
jnecus Oct 9, 2020
42a6bda
Update test_store.py
jnecus Oct 9, 2020
7602095
Update test_store.py
jnecus Oct 9, 2020
740a1da
Update test_store.py
jnecus Oct 11, 2020
b923b19
Update test_store.py
jnecus Oct 11, 2020
5624e99
Merge remote-tracking branch 'upstream/master'
jnecus Oct 11, 2020
c2d16d5
Merge remote-tracking branch 'upstream/master'
jnecus Oct 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,11 @@ if mods:
sys.exit(len(mods))
"
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check code for instances of os.remove' ; echo $MSG
#TODO: insert check here Issue #34384
RET=$(($RET + $?)) ; echo $MSG "DONE"



MSG='Check code for instances of os.remove' ; echo $MSG
invgrep -R --include="*.py*" -E "os.remove" pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi

### DOCTESTS ###
Expand Down
29 changes: 15 additions & 14 deletions pandas/tests/io/excel/test_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas._testing as tm

from pandas.io.excel import ExcelWriter, _OpenpyxlWriter
from pandas.testing import ensure_clean
from pandas._testing import ensure_clean

openpyxl = pytest.importorskip("openpyxl")

Expand Down Expand Up @@ -109,16 +109,17 @@ def test_write_append_mode(ext, mode, expected):


def test_to_excel_with_openpyxl_engine(ext, tmpdir):
# GH 29854
df1 = DataFrame({"A": np.linspace(1, 10, 10)})
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
df = pd.concat([df1, df2], axis=1)
styled = df.style.applymap(
lambda val: "color: %s" % ("red" if val < 0 else "black")
).highlight_max()

filename = tmpdir / "styled.xlsx"
styled.to_excel(filename, engine="openpyxl")

assert filename.exists()
ensure_clean(filename)

with ensure_clean('styled.xlsx') as filename:
# GH 29854
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the issue number comment outside of the context manager?

df1 = DataFrame({"A": np.linspace(1, 10, 10)})
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
df = pd.concat([df1, df2], axis=1)
styled = df.style.applymap(
lambda val: "color: %s" % ("red" if val < 0 else "black")
).highlight_max()

styled.to_excel(filename, engine="openpyxl")

assert filename.exists()

5 changes: 3 additions & 2 deletions pandas/tests/io/pytables/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from pandas.io.pytables import HDFStore
from pandas.testing import ensure_clean
from pandas._testing import ensure_clean

tables = pytest.importorskip("tables")
# set these parameters so we don't have file sharing
Expand All @@ -17,7 +17,8 @@
def safe_remove(path):
if path is not None:
try:
ensure_clean(path)
with ensure_clean(path) as filename:
ensure_clean(filename)
except OSError:
pass

Expand Down