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 all commits
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
26 changes: 11 additions & 15 deletions pandas/tests/io/excel/test_openpyxl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import numpy as np
import pytest

Expand Down Expand Up @@ -107,17 +105,15 @@ def test_write_append_mode(ext, mode, expected):
assert wb2.worksheets[index]["A1"].value == cell_value


def test_to_excel_with_openpyxl_engine(ext, tmpdir):
def test_to_excel_with_openpyxl_engine(ext):
# 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()
os.remove(filename)
with tm.ensure_clean(ext) as filename:

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")
47 changes: 15 additions & 32 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
import pandas._testing as tm
from pandas.tests.io.pytables.common import (
_maybe_remove,
create_tempfile,
ensure_clean_path,
ensure_clean_store,
safe_close,
safe_remove,
tables,
)

Expand Down Expand Up @@ -80,33 +78,25 @@ def test_format_kwarg_in_constructor(self, setup_path):

msg = "format is not a defined argument for HDFStore"

with ensure_clean_path(setup_path) as path:
with tm.ensure_clean(setup_path) as path:
with pytest.raises(ValueError, match=msg):
HDFStore(path, format="table")

def test_context(self, setup_path):
path = create_tempfile(setup_path)
try:
with HDFStore(path) as tbl:
raise ValueError("blah")
except ValueError:
pass
finally:
safe_remove(path)

try:
with tm.ensure_clean(setup_path) as path:
try:
with HDFStore(path) as tbl:
raise ValueError("blah")
except ValueError:
pass
with tm.ensure_clean(setup_path) as path:
with HDFStore(path) as tbl:
tbl["a"] = tm.makeDataFrame()

with HDFStore(path) as tbl:
assert len(tbl) == 1
assert type(tbl["a"]) == DataFrame
finally:
safe_remove(path)

def test_conv_read_write(self, setup_path):
path = create_tempfile(setup_path)
try:
with tm.ensure_clean() as path:

def roundtrip(key, obj, **kwargs):
obj.to_hdf(path, key, **kwargs)
Expand All @@ -127,9 +117,6 @@ def roundtrip(key, obj, **kwargs):
result = read_hdf(path, "table", where=["index>2"])
tm.assert_frame_equal(df[df.index > 2], result)

finally:
safe_remove(path)

def test_long_strings(self, setup_path):

# GH6166
Expand Down Expand Up @@ -605,7 +592,7 @@ def test_reopen_handle(self, setup_path):

def test_open_args(self, setup_path):

with ensure_clean_path(setup_path) as path:
with tm.ensure_clean(setup_path) as path:

df = tm.makeDataFrame()

Expand All @@ -621,8 +608,8 @@ def test_open_args(self, setup_path):

store.close()

# the file should not have actually been written
assert not os.path.exists(path)
# the file should not have actually been written
assert not os.path.exists(path)

def test_flush(self, setup_path):

Expand Down Expand Up @@ -4194,7 +4181,6 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs):
import tempfile

fd, new_f = tempfile.mkstemp()

tstore = store.copy(
new_f, keys=keys, propindexes=propindexes, **kwargs
)
Expand Down Expand Up @@ -4225,20 +4211,17 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs):
os.close(fd)
except (OSError, ValueError):
pass
safe_remove(new_f)
os.remove(new_f)

# new table
df = tm.makeDataFrame()

try:
path = create_tempfile(setup_path)
with tm.ensure_clean() as path:
st = HDFStore(path)
st.append("df", df, data_columns=["A"])
st.close()
do_copy(f=path)
do_copy(f=path, propindexes=False)
finally:
safe_remove(path)

def test_store_datetime_fractional_secs(self, setup_path):

Expand Down Expand Up @@ -4677,7 +4660,7 @@ def test_read_hdf_generic_buffer_errors(self):

def test_invalid_complib(self, setup_path):
df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE"))
with ensure_clean_path(setup_path) as path:
with tm.ensure_clean(setup_path) as path:
with pytest.raises(ValueError):
df.to_hdf(path, "df", complib="foolib")

Expand Down