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
21 changes: 10 additions & 11 deletions geoh5py/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def close(self):

self.repack = False

if isinstance(self._h5file, BytesIO):
self._h5file.seek(0)

@property
def contributors(self) -> np.ndarray:
"""
Expand Down Expand Up @@ -1296,17 +1299,13 @@ def _create_h5(self) -> h5py.File:
"""
Generate a new geoh5 file with core structure.
"""
if isinstance(self.h5file, BytesIO):
self._geoh5 = h5py.File(self.h5file, "a")

elif isinstance(self.h5file, Path):
self._geoh5 = h5py.File(
self.h5file,
"x",
fs_strategy="page",
page_buf_size=DEFAULT_PAGE_BUF_SIZE,
)

self._geoh5 = h5py.File(
self.h5file,
"x",
fs_strategy="page",
page_buf_size=DEFAULT_PAGE_BUF_SIZE,
libver=("v110", "v114"),
)
H5Writer.init_geoh5(self._geoh5, self)

return self._geoh5
Expand Down
4 changes: 2 additions & 2 deletions tests/add_filename_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@


def test_add_file(tmp_path: Path):
workspace = Workspace(tmp_path / "test.geoh5")
workspace_copy = Workspace()
workspace = Workspace.create(tmp_path / f"{__name__}.geoh5")
workspace_copy = Workspace.create(tmp_path / f"{__name__}_copy.geoh5")
with pytest.warns(UserWarning, match="No 'vertices' provided."):
curve = Curve.create(workspace)
group = ContainerGroup.create(workspace)
Expand Down
3 changes: 2 additions & 1 deletion tests/point_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def test_create_point_data(tmp_path):
# Generate a random cloud of points
values = np.random.randn(12)
h5file_path = tmp_path / r"testPoints.geoh5"
workspace = Workspace.create(h5file_path)
workspace = Workspace()
points = Points.create(workspace, vertices=np.random.randn(12, 3), allow_move=False)
data = points.add_data({"DataValues": {"association": "VERTEX", "values": values}})

workspace.save_as(h5file_path)
with pytest.raises(ValueError, match="Association flag should be one of"):
points.add_data({"test": {"association": "ABC", "values": values}})

Expand Down
8 changes: 4 additions & 4 deletions tests/workspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def test_workspace_from_kwargs(tmp_path: Path):
f"Error changing value for attribute {key}."
)

assert workspace.geoh5.libver == ("earliest", "v114")
assert workspace.geoh5.libver == ("v110", "v114")
workspace.close()


def test_empty_workspace(tmp_path):
Workspace.create(
with Workspace.create(
tmp_path / r"test.geoh5",
).close()

) as workspace:
assert workspace.geoh5.libver == ("v110", "v114")
Comment thread
sebhmg marked this conversation as resolved.
with File(tmp_path / r"test.geoh5", "r+") as file:
del file["GEOSCIENCE"]["Groups"]
del file["GEOSCIENCE"]["Data"]
Expand Down
Loading