Skip to content
Open
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
15 changes: 9 additions & 6 deletions pandas/tests/io/pytables/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pandas as pd
from pandas import (
DataFrame,
HDFStore,
Series,
)
import pandas._testing as tm
from pandas.tests.io.pytables.common import ensure_clean_store

from pandas.io.pytables import read_hdf

Expand Down Expand Up @@ -103,7 +103,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 +140,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 +157,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 +185,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) as store:
store.append("df", df, data_columns=["b"])
store.append("df", df)
result = store.select("df")
Expand Down
Loading