From c08b3bbb38f865fbd6747fe11695b5aa949eaa04 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 24 Jun 2026 16:02:11 +0200 Subject: [PATCH 1/2] Update error message in ParticleFile writing --- src/parcels/_core/particlefile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/parcels/_core/particlefile.py b/src/parcels/_core/particlefile.py index 7a3fc9d64..0c9173bdf 100644 --- a/src/parcels/_core/particlefile.py +++ b/src/parcels/_core/particlefile.py @@ -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 = {} From 6a20d765594fd129a54a934a35bd3159b676c46b Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 24 Jun 2026 16:28:46 +0200 Subject: [PATCH 2/2] Add test --- tests/test_particlefile.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_particlefile.py b/tests/test_particlefile.py index dc0e232c1..c98385d48 100755 --- a/tests/test_particlefile.py +++ b/tests/test_particlefile.py @@ -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")