Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 10 additions & 8 deletions pandas/tests/io/pytables/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import pandas as pd
from pandas import (
DataFrame,
HDFStore,
Series,
read_hdf,
)
import pandas._testing as tm
from pandas.tests.io.pytables.common import ensure_clean_store

from pandas.io.pytables import read_hdf


def test_complex_fixed(tmp_path, setup_path):
Expand Down Expand Up @@ -103,7 +102,8 @@ def test_complex_mixed_table(tmp_path, setup_path):
index=list("abcd"),
)

with ensure_clean_store(setup_path) as store:
path = tmp_path / setup_path
with HDFStore(path) as store:
store.append("df", df, data_columns=["A", "B"])
result = store.select("df", where="A>2")
tm.assert_frame_equal(df.loc[df.A > 2], result)
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_complex_across_dimensions(tmp_path, setup_path):
tm.assert_frame_equal(df, reread)


def test_complex_indexing_error(setup_path):
def test_complex_indexing_error(tmp_path, setup_path):
complex128 = np.array(
[1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128
)
Expand All @@ -156,7 +156,8 @@ def test_complex_indexing_error(setup_path):
"values to data_columns when initializing the table."
)

with ensure_clean_store(setup_path) as store:
path = tmp_path / setup_path
with HDFStore(path) as store:
with pytest.raises(TypeError, match=msg):
store.append("df", df, data_columns=["C"])

Expand All @@ -183,15 +184,16 @@ def test_complex_series_error(tmp_path, setup_path):
tm.assert_series_equal(s, reread)


def test_complex_append(setup_path):
def test_complex_append(tmp_path, setup_path):
df = DataFrame(
{
"a": np.random.default_rng(2).standard_normal(100).astype(np.complex128),
"b": np.random.default_rng(2).standard_normal(100),
}
)

with ensure_clean_store(setup_path) as store:
path = tmp_path / setup_path
with HDFStore(path, mode="a") as store:
store.append("df", df, data_columns=["b"])
store.append("df", df)
result = store.select("df")
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/io/pytables/test_file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
)
from pandas.tests.io.pytables.common import (
_maybe_remove,
ensure_clean_store,
tables,
)

Expand Down Expand Up @@ -188,8 +187,8 @@ def test_open_args(tmp_path, setup_path, using_infer_string):
assert not os.path.exists(path)


def test_flush(setup_path):
with ensure_clean_store(setup_path) as store:
def test_flush(tmp_path, setup_path):
with HDFStore(tmp_path / setup_path) as store:
store["a"] = Series(range(5))
store.flush()
store.flush(fsync=True)
Expand Down Expand Up @@ -316,8 +315,8 @@ def test_complibs(tmp_path, lvl, lib, request):
@pytest.mark.skipif(
not is_platform_little_endian(), reason="reason platform is not little endian"
)
def test_encoding(setup_path):
with ensure_clean_store(setup_path) as store:
def test_encoding(tmp_path, setup_path):
with HDFStore(tmp_path / setup_path) as store:
df = DataFrame({"A": "foo", "B": "bar"}, index=range(5))
df.loc[2, "A"] = np.nan
df.loc[3, "B"] = np.nan
Expand Down
Loading