-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 49 commits
a4d6ae4
64de146
80e7f26
d4ac552
24365ab
6266771
e1ccaae
4df4bc7
abce52f
a0de23b
ae63191
054ade5
a40ab46
b749f8e
14e2c79
0d68e31
dce777b
12ff5a5
100d2ad
abff45c
38aefad
df79c64
ea16a0a
a6732f9
a931e2a
1db905a
442d83c
dbb3d74
2799d13
3bef5f4
bb79fa3
6c3108e
3f2af9d
6cc69f0
02eeab1
3da1b95
2fb17a3
4034fd6
af8b575
7a3011e
ee95e71
7791b7d
045d797
72ec987
f812a39
6575419
22258de
3e41dc5
b3e8d96
2063623
9de691c
de874af
3309222
4c8091c
9474ebc
42a6bda
7602095
740a1da
b923b19
5624e99
c2d16d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
) | ||
|
||
|
@@ -79,33 +77,31 @@ 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 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) | ||
with tm.ensure_clean() as path: | ||
try: | ||
with HDFStore(path) as tbl: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError("blah") | ||
except ValueError: | ||
pass | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
with HDFStore(path) as tbl: | ||
tbl["a"] = tm.makeDataFrame() | ||
except ValueError: | ||
pass | ||
try: | ||
with HDFStore(path) as tbl: | ||
assert len(tbl) == 1 | ||
assert type(tbl["a"]) == DataFrame | ||
except ValueError: | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure we want to pass here and on L95? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't modified the existing structure here. What would you suggest to change it to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
|
||
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) | ||
|
@@ -126,9 +122,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 | ||
|
@@ -604,7 +597,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() | ||
|
||
|
@@ -620,8 +613,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) | ||
jnecus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_flush(self, setup_path): | ||
|
||
|
@@ -4230,9 +4223,9 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): | |
|
||
fd, new_f = tempfile.mkstemp() | ||
|
||
tstore = store.copy( | ||
new_f, keys=keys, propindexes=propindexes, **kwargs | ||
) | ||
tstore = store.copy( | ||
new_f, keys=keys, propindexes=propindexes, **kwargs | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the changed indentation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was changed by running the 'black' command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (in general, let the the person commenting/questioning hit the "resolve conversation" button) if black did this, please undo it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, noted re: the resolve conversation button, sorry about that. Will undo indentation now 👍 |
||
|
||
# check keys | ||
if keys is None: | ||
|
@@ -4260,20 +4253,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): | ||
|
||
|
@@ -4713,7 +4703,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") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does "tempdir" not need to come in here?