Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH/FIX: support pathlib.Path for ParticleGroup filenames #81

Merged
merged 1 commit into from
Oct 25, 2024
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
5 changes: 3 additions & 2 deletions pmd_beamphysics/particles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import os
import pathlib
from copy import deepcopy

import numpy as np
Expand Down Expand Up @@ -178,7 +179,7 @@ def __init__(self, h5=None, data=None):

if h5:
# Allow filename
if isinstance(h5, str):
if isinstance(h5, (str, pathlib.Path)):
fname = os.path.expandvars(h5)
assert os.path.exists(fname), f"File does not exist: {fname}"

Expand Down Expand Up @@ -974,7 +975,7 @@ def write(self, h5, name=None):
Writes to an open h5 handle, or new file if h5 is a str.
"""
if isinstance(h5, str):
if isinstance(h5, (str, pathlib.Path)):
fname = os.path.expandvars(h5)
g = File(fname, "w")
pmd_init(g, basePath="/", particlesPath=".")
Expand Down
Loading