Skip to content

Commit 63bcd77

Browse files
committed
Replace ensure_clean_store instances with temp_file
1 parent 1fd184d commit 63bcd77

File tree

1 file changed

+50
-51
lines changed

1 file changed

+50
-51
lines changed

pandas/tests/io/pytables/test_store.py

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
)
2929
from pandas.tests.io.pytables.common import (
3030
_maybe_remove,
31-
ensure_clean_store,
3231
)
3332

3433
from pandas.io.pytables import (
@@ -100,14 +99,14 @@ def create_h5_and_return_checksum(tmp_path, track_times):
10099
assert checksum_0_tt_true != checksum_1_tt_true
101100

102101

103-
def test_iter_empty(setup_path):
104-
with ensure_clean_store(setup_path) as store:
102+
def test_iter_empty(temp_file):
103+
with HDFStore(temp_file) as store:
105104
# GH 12221
106105
assert list(store) == []
107106

108107

109-
def test_repr(setup_path, performance_warning, using_infer_string):
110-
with ensure_clean_store(setup_path) as store:
108+
def test_repr(temp_file, performance_warning, using_infer_string):
109+
with HDFStore(temp_file) as store:
111110
repr(store)
112111
store.info()
113112
store["a"] = Series(
@@ -154,7 +153,7 @@ def test_repr(setup_path, performance_warning, using_infer_string):
154153
store.info()
155154

156155
# storers
157-
with ensure_clean_store(setup_path) as store:
156+
with HDFStore(temp_file) as store:
158157
df = DataFrame(
159158
1.1 * np.arange(120).reshape((30, 4)),
160159
columns=Index(list("ABCD"), dtype=object),
@@ -167,8 +166,8 @@ def test_repr(setup_path, performance_warning, using_infer_string):
167166
str(s)
168167

169168

170-
def test_contains(setup_path):
171-
with ensure_clean_store(setup_path) as store:
169+
def test_contains(temp_file):
170+
with HDFStore(temp_file) as store:
172171
store["a"] = Series(
173172
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
174173
)
@@ -202,8 +201,8 @@ def test_contains(setup_path):
202201
assert "node())" in store
203202

204203

205-
def test_versioning(setup_path):
206-
with ensure_clean_store(setup_path) as store:
204+
def test_versioning(temp_file):
205+
with HDFStore(temp_file) as store:
207206
store["a"] = Series(
208207
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
209208
)
@@ -259,7 +258,7 @@ def test_versioning(setup_path):
259258
),
260259
],
261260
)
262-
def test_walk(where, expected):
261+
def test_walk(temp_path, where, expected):
263262
# GH10143
264263
objs = {
265264
"df1": DataFrame([1, 2, 3]),
@@ -273,7 +272,7 @@ def test_walk(where, expected):
273272
"tb2": np.array([(7, 8, 9), (10, 11, 12)], dtype="i,i,i"),
274273
}
275274

276-
with ensure_clean_store("walk_groups.hdf", mode="w") as store:
275+
with HDFStore(temp_path / "walk_groups.hdf", mode="w") as store:
277276
store.put("/first_group/df1", objs["df1"])
278277
store.put("/first_group/df2", objs["df2"])
279278
store.put("/second_group/df3", objs["df3"])
@@ -299,8 +298,8 @@ def test_walk(where, expected):
299298
tm.assert_series_equal(obj, objs[leaf])
300299

301300

302-
def test_getattr(setup_path):
303-
with ensure_clean_store(setup_path) as store:
301+
def test_getattr(temp_file):
302+
with HDFStore(temp_file) as store:
304303
s = Series(
305304
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
306305
)
@@ -403,8 +402,8 @@ def test_to_hdf_errors(tmp_path, format, setup_path, using_infer_string):
403402
tm.assert_series_equal(result, expected)
404403

405404

406-
def test_create_table_index(setup_path):
407-
with ensure_clean_store(setup_path) as store:
405+
def test_create_table_index(temp_file):
406+
with HDFStore(temp_file) as store:
408407

409408
def col(t, column):
410409
return getattr(store.get_storer(t).table.cols, column)
@@ -436,10 +435,10 @@ def col(t, column):
436435
store.create_table_index("f2")
437436

438437

439-
def test_create_table_index_data_columns_argument(setup_path):
438+
def test_create_table_index_data_columns_argument(temp_file):
440439
# GH 28156
441440

442-
with ensure_clean_store(setup_path) as store:
441+
with HDFStore(temp_file) as store:
443442

444443
def col(t, column):
445444
return getattr(store.get_storer(t).table.cols, column)
@@ -470,22 +469,22 @@ def col(t, column):
470469
store.create_table_index("f", columns=["string2"])
471470

472471

473-
def test_mi_data_columns(setup_path):
472+
def test_mi_data_columns(temp_file):
474473
# GH 14435
475474
idx = MultiIndex.from_arrays(
476475
[date_range("2000-01-01", periods=5), range(5)], names=["date", "id"]
477476
)
478477
df = DataFrame({"a": [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx)
479478

480-
with ensure_clean_store(setup_path) as store:
479+
with HDFStore(temp_file) as store:
481480
store.append("df", df, data_columns=True)
482481

483482
actual = store.select("df", where="id == 1")
484483
expected = df.iloc[[1], :]
485484
tm.assert_frame_equal(actual, expected)
486485

487486

488-
def test_table_mixed_dtypes(setup_path):
487+
def test_table_mixed_dtypes(temp_file):
489488
# frame
490489
df = DataFrame(
491490
1.1 * np.arange(120).reshape((30, 4)),
@@ -506,12 +505,12 @@ def test_table_mixed_dtypes(setup_path):
506505
df.loc[df.index[3:6], ["obj1"]] = np.nan
507506
df = df._consolidate()
508507

509-
with ensure_clean_store(setup_path) as store:
508+
with HDFStore(temp_file) as store:
510509
store.append("df1_mixed", df)
511510
tm.assert_frame_equal(store.select("df1_mixed"), df)
512511

513512

514-
def test_calendar_roundtrip_issue(setup_path):
513+
def test_calendar_roundtrip_issue(temp_file):
515514
# 8591
516515
# doc example from tseries holiday section
517516
weekmask_egypt = "Sun Mon Tue Wed Thu"
@@ -528,7 +527,7 @@ def test_calendar_roundtrip_issue(setup_path):
528527

529528
s = Series(dts.weekday, dts).map(Series("Mon Tue Wed Thu Fri Sat Sun".split()))
530529

531-
with ensure_clean_store(setup_path) as store:
530+
with HDFStore(temp_file) as store:
532531
store.put("fixed", s)
533532
result = store.select("fixed")
534533
tm.assert_series_equal(result, s)
@@ -538,8 +537,8 @@ def test_calendar_roundtrip_issue(setup_path):
538537
tm.assert_series_equal(result, s)
539538

540539

541-
def test_remove(setup_path):
542-
with ensure_clean_store(setup_path) as store:
540+
def test_remove(temp_file):
541+
with HDFStore(temp_file) as store:
543542
ts = Series(
544543
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
545544
)
@@ -583,8 +582,8 @@ def test_remove(setup_path):
583582
assert len(store) == 0
584583

585584

586-
def test_same_name_scoping(setup_path):
587-
with ensure_clean_store(setup_path) as store:
585+
def test_same_name_scoping(temp_file):
586+
with HDFStore(temp_file) as store:
588587
df = DataFrame(
589588
np.random.default_rng(2).standard_normal((20, 2)),
590589
index=date_range("20130101", periods=20, unit="ns"),
@@ -606,15 +605,15 @@ def test_same_name_scoping(setup_path):
606605
tm.assert_frame_equal(result, expected)
607606

608607

609-
def test_store_index_name(setup_path):
608+
def test_store_index_name(temp_file):
610609
df = DataFrame(
611610
1.1 * np.arange(120).reshape((30, 4)),
612611
columns=Index(list("ABCD")),
613612
index=Index([f"i-{i}" for i in range(30)]),
614613
)
615614
df.index.name = "foo"
616615

617-
with ensure_clean_store(setup_path) as store:
616+
with HDFStore(temp_file) as store:
618617
store["frame"] = df
619618
recons = store["frame"]
620619
tm.assert_frame_equal(recons, df)
@@ -653,22 +652,22 @@ def test_store_index_name_numpy_str(tmp_path, table_format, setup_path, unit, tz
653652
assert isinstance(df2.columns.name, str)
654653

655654

656-
def test_store_series_name(setup_path):
655+
def test_store_series_name(temp_file):
657656
df = DataFrame(
658657
1.1 * np.arange(120).reshape((30, 4)),
659658
columns=Index(list("ABCD")),
660659
index=Index([f"i-{i}" for i in range(30)]),
661660
)
662661
series = df["A"]
663662

664-
with ensure_clean_store(setup_path) as store:
663+
with HDFStore(temp_file) as store:
665664
store["series"] = series
666665
recons = store["series"]
667666
tm.assert_series_equal(recons, series)
668667

669668

670-
def test_overwrite_node(setup_path):
671-
with ensure_clean_store(setup_path) as store:
669+
def test_overwrite_node(temp_file):
670+
with HDFStore(temp_file) as store:
672671
store["a"] = DataFrame(
673672
np.random.default_rng(2).standard_normal((10, 4)),
674673
columns=Index(list("ABCD")),
@@ -682,14 +681,14 @@ def test_overwrite_node(setup_path):
682681
tm.assert_series_equal(store["a"], ts)
683682

684683

685-
def test_coordinates(setup_path):
684+
def test_coordinates(temp_file):
686685
df = DataFrame(
687686
np.random.default_rng(2).standard_normal((10, 4)),
688687
columns=Index(list("ABCD")),
689688
index=date_range("2000-01-01", periods=10, freq="B"),
690689
)
691690

692-
with ensure_clean_store(setup_path) as store:
691+
with HDFStore(temp_file) as store:
693692
_maybe_remove(store, "df")
694693
store.append("df", df)
695694

@@ -739,7 +738,7 @@ def test_coordinates(setup_path):
739738
# but expect freq="18B"
740739

741740
# pass array/mask as the coordinates
742-
with ensure_clean_store(setup_path) as store:
741+
with HDFStore(temp_file) as store:
743742
df = DataFrame(
744743
np.random.default_rng(2).standard_normal((1000, 2)),
745744
index=date_range("20000101", periods=1000),
@@ -800,8 +799,8 @@ def test_coordinates(setup_path):
800799
tm.assert_frame_equal(result, expected)
801800

802801

803-
def test_start_stop_table(setup_path):
804-
with ensure_clean_store(setup_path) as store:
802+
def test_start_stop_table(temp_file):
803+
with HDFStore(temp_file) as store:
805804
# table
806805
df = DataFrame(
807806
{
@@ -822,9 +821,9 @@ def test_start_stop_table(setup_path):
822821
tm.assert_frame_equal(result, expected)
823822

824823

825-
def test_start_stop_multiple(setup_path):
824+
def test_start_stop_multiple(temp_file):
826825
# GH 16209
827-
with ensure_clean_store(setup_path) as store:
826+
with HDFStore(temp_file) as store:
828827
df = DataFrame({"foo": [1, 2], "bar": [1, 2]})
829828

830829
store.append_to_multiple(
@@ -837,8 +836,8 @@ def test_start_stop_multiple(setup_path):
837836
tm.assert_frame_equal(result, expected)
838837

839838

840-
def test_start_stop_fixed(setup_path):
841-
with ensure_clean_store(setup_path) as store:
839+
def test_start_stop_fixed(temp_file):
840+
with HDFStore(temp_file) as store:
842841
# fixed, GH 8287
843842
df = DataFrame(
844843
{
@@ -883,12 +882,12 @@ def test_start_stop_fixed(setup_path):
883882
df.iloc[8:10, -2] = np.nan
884883

885884

886-
def test_select_filter_corner(setup_path, request):
885+
def test_select_filter_corner(temp_file, request):
887886
df = DataFrame(np.random.default_rng(2).standard_normal((50, 100)))
888887
df.index = [f"{c:3d}" for c in df.index]
889888
df.columns = [f"{c:3d}" for c in df.columns]
890889

891-
with ensure_clean_store(setup_path) as store:
890+
with HDFStore(temp_file) as store:
892891
store.put("frame", df, format="table")
893892

894893
request.applymarker(
@@ -921,7 +920,7 @@ def test_path_pathlib():
921920

922921

923922
@pytest.mark.parametrize("start, stop", [(0, 2), (1, 2), (None, None)])
924-
def test_contiguous_mixed_data_table(start, stop, setup_path):
923+
def test_contiguous_mixed_data_table(start, stop, temp_file):
925924
# GH 17021
926925
df = DataFrame(
927926
{
@@ -930,7 +929,7 @@ def test_contiguous_mixed_data_table(start, stop, setup_path):
930929
}
931930
)
932931

933-
with ensure_clean_store(setup_path) as store:
932+
with HDFStore(temp_file) as store:
934933
store.append("test_dataset", df)
935934

936935
result = store.select("test_dataset", start=start, stop=stop)
@@ -1017,14 +1016,14 @@ def test_duplicate_column_name(tmp_path, setup_path):
10171016
assert other.equals(df)
10181017

10191018

1020-
def test_preserve_timedeltaindex_type(setup_path, unit):
1019+
def test_preserve_timedeltaindex_type(temp_file, unit):
10211020
# GH9635
10221021
df = DataFrame(np.random.default_rng(2).normal(size=(10, 5)))
10231022
df.index = timedelta_range(
10241023
start="0s", periods=10, freq="1s", name="example", unit=unit
10251024
)
10261025

1027-
with ensure_clean_store(setup_path) as store:
1026+
with HDFStore(temp_file) as store:
10281027
store["df"] = df
10291028
tm.assert_frame_equal(store["df"], df)
10301029

@@ -1090,10 +1089,10 @@ def test_to_hdf_with_object_column_names_should_run(tmp_path, setup_path, dtype)
10901089
assert len(result)
10911090

10921091

1093-
def test_hdfstore_strides(setup_path):
1092+
def test_hdfstore_strides(temp_file):
10941093
# GH22073
10951094
df = DataFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})
1096-
with ensure_clean_store(setup_path) as store:
1095+
with HDFStore(temp_file) as store:
10971096
store.put("df", df)
10981097
assert df["a"].values.strides == store["df"]["a"].values.strides
10991098

0 commit comments

Comments
 (0)