Skip to content

Commit

Permalink
Merge pull request #81 from ken-lauer/enh_pathlib
Browse files Browse the repository at this point in the history
ENH/FIX: support pathlib.Path for ParticleGroup filenames
  • Loading branch information
ChristopherMayes authored Oct 25, 2024
2 parents 33064e2 + c828e6e commit 853e98f
Showing 1 changed file with 3 additions and 2 deletions.
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

0 comments on commit 853e98f

Please sign in to comment.