Skip to content

Commit 7c646a6

Browse files
Replace ensure_clean_store with new fixture in test_complex.py
Add HDFStore and remove ensure_clean_store imports, use tmp_path / setup_path with HDFStore instead.
1 parent 8e5ef67 commit 7c646a6

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pandas/tests/io/pytables/test_complex.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
Series,
88
)
99
import pandas._testing as tm
10-
from pandas.tests.io.pytables.common import ensure_clean_store
10+
from pandas.io.pytables import (
11+
HDFStore,
12+
read_hdf,
13+
)
1114

12-
from pandas.io.pytables import read_hdf
1315

1416

1517
def test_complex_fixed(tmp_path, setup_path):
@@ -103,11 +105,13 @@ def test_complex_mixed_table(tmp_path, setup_path):
103105
index=list("abcd"),
104106
)
105107

106-
with ensure_clean_store(setup_path) as store:
108+
path = tmp_path / setup_path
109+
with HDFStore(path) as store:
107110
store.append("df", df, data_columns=["A", "B"])
108111
result = store.select("df", where="A>2")
109112
tm.assert_frame_equal(df.loc[df.A > 2], result)
110113

114+
111115
path = tmp_path / setup_path
112116
df.to_hdf(path, key="df", format="table")
113117
reread = read_hdf(path, "df")
@@ -139,7 +143,7 @@ def test_complex_across_dimensions(tmp_path, setup_path):
139143
tm.assert_frame_equal(df, reread)
140144

141145

142-
def test_complex_indexing_error(setup_path):
146+
def test_complex_indexing_error(tmp_path, setup_path):
143147
complex128 = np.array(
144148
[1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128
145149
)
@@ -156,11 +160,13 @@ def test_complex_indexing_error(setup_path):
156160
"values to data_columns when initializing the table."
157161
)
158162

159-
with ensure_clean_store(setup_path) as store:
163+
path = tmp_path / setup_path
164+
with HDFStore(path) as store:
160165
with pytest.raises(TypeError, match=msg):
161166
store.append("df", df, data_columns=["C"])
162167

163168

169+
164170
def test_complex_series_error(tmp_path, setup_path):
165171
complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j])
166172
s = Series(complex128, index=list("abcd"))
@@ -183,16 +189,18 @@ def test_complex_series_error(tmp_path, setup_path):
183189
tm.assert_series_equal(s, reread)
184190

185191

186-
def test_complex_append(setup_path):
192+
def test_complex_append(tmp_path, setup_path):
187193
df = DataFrame(
188194
{
189195
"a": np.random.default_rng(2).standard_normal(100).astype(np.complex128),
190196
"b": np.random.default_rng(2).standard_normal(100),
191197
}
192198
)
193199

194-
with ensure_clean_store(setup_path) as store:
200+
path = tmp_path / setup_path
201+
with HDFStore(path, mode="a") as store:
195202
store.append("df", df, data_columns=["b"])
196203
store.append("df", df)
197204
result = store.select("df")
198205
tm.assert_frame_equal(pd.concat([df, df], axis=0), result)
206+

0 commit comments

Comments
 (0)