Skip to content

Commit

Permalink
Fix nice array for single element list-like
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherMayes committed Nov 19, 2024
1 parent 8be7b4e commit 03f7519
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions pmd_beamphysics/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def nice_array(a):
if np.isscalar(a):
x = a
elif len(a) == 1:
a = np.asarray(a)
x = a[0]
else:
a = np.array(a)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_nice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pmd_beamphysics.units import nice_array
import numpy as np


def test_nice_array():
nice_array(1)

nice_array([1])

nice_array(
[
1,
2,
]
)

nice_array(np.array([1, 2]))

0 comments on commit 03f7519

Please sign in to comment.