Skip to content
Merged
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
46 changes: 22 additions & 24 deletions pandas/tests/io/pytables/test_file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,28 @@ def test_reopen_handle(tmp_path, setup_path):
assert not store.is_open


def test_open_args(setup_path, using_infer_string):
with tm.ensure_clean(setup_path) as path:
df = DataFrame(
1.1 * np.arange(120).reshape((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=Index([f"i-{i}" for i in range(30)], dtype=object),
)
def test_open_args(tmp_path, setup_path, using_infer_string):
path = tmp_path / setup_path
df = DataFrame(
1.1 * np.arange(120).reshape((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=Index([f"i-{i}" for i in range(30)], dtype=object),
)

# create an in memory store
store = HDFStore(
path, mode="a", driver="H5FD_CORE", driver_core_backing_store=0
)
store["df"] = df
store.append("df2", df)
# create an in memory store
store = HDFStore(path, mode="a", driver="H5FD_CORE", driver_core_backing_store=0)
store["df"] = df
store.append("df2", df)

expected = df.copy()
if using_infer_string:
expected.index = expected.index.astype("str")
expected.columns = expected.columns.astype("str")
expected = df.copy()
if using_infer_string:
expected.index = expected.index.astype("str")
expected.columns = expected.columns.astype("str")

tm.assert_frame_equal(store["df"], expected)
tm.assert_frame_equal(store["df2"], expected)
tm.assert_frame_equal(store["df"], expected)
tm.assert_frame_equal(store["df2"], expected)

store.close()
store.close()

# the file should not have actually been written
assert not os.path.exists(path)
Expand Down Expand Up @@ -507,7 +505,7 @@ def test_multiple_open_close(tmp_path, setup_path):
store.df


def test_fspath():
with tm.ensure_clean("foo.h5") as path:
with HDFStore(path) as store:
assert os.fspath(store) == str(path)
def test_fspath(tmp_path):
path = tmp_path / "foo.h5"
with HDFStore(path) as store:
assert os.fspath(store) == str(path)
Loading