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
6 changes: 4 additions & 2 deletions src/parcels/_core/particlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ def __init__(

if path.exists():
if mode is None:
raise ValueError(f"{path=!r} already exists. Use mode='w' or use a new path.")
msg = f"Path '{path}' already exists. Use mode='w' or use a new path."
raise ValueError(msg)
if mode == "w":
path.unlink()
if not path.parent.exists():
raise ValueError(f"Folder location for {path=!r} does not exist. Create the folder location first.")
msg = f"Folder location for '{path} does not exist. Create the folder location first."
raise ValueError(msg)

self.metadata = {}

Expand Down
12 changes: 12 additions & 0 deletions tests/test_particlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,18 @@ def test_particlefile_init_existing_path_modes(fieldset, tmp_parquet):
assert len(df_first) == len(df_overwrite)


def test_particlefile_init_existing_path_no_mode(tmp_parquet):
tmp_parquet.touch()
with pytest.raises(ValueError, match="already exists"):
ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s"))


def test_particlefile_init_nonexistent_parent(tmp_path):
path = tmp_path / "nonexistent_dir" / "file.parquet"
with pytest.raises(ValueError, match="does not exist"):
ParticleFile(path, outputdt=np.timedelta64(1, "s"))


def test_particlefile_init_invalid_mode(tmp_parquet):
with pytest.raises(ValueError, match="Invalid mode value"):
ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s"), mode="something-else")
Expand Down
Loading