Skip to content
Merged
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
7 changes: 7 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.6.17
------

Bug Fixes

- Fixed bug with bools not converted in numpy_util.dict2arr

0.6.16
------

Expand Down
2 changes: 1 addition & 1 deletion esutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class for gauss-legendre integration, which relies on the gauleg C++ extension.

import sys

__version__ = "0.6.16"
__version__ = "0.6.17"

def version():
return __version__
Expand Down
10 changes: 6 additions & 4 deletions esutil/numpy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ def dict2array(d, sort=False, keys=None):
if key not in d:
raise KeyError("Requested key %s not in dictionary" % key)

if not isinstance(d[key], (int, float, str)):
if not isinstance(d[key], (int, float, str, bool)):
try:
strval = "%s" % d[key]
val = eval(strval)
Expand All @@ -1666,15 +1666,17 @@ def dict2array(d, sort=False, keys=None):
else:
val = d[key]

if isinstance(val, int):
if isinstance(val, bool):
dt = bool
elif isinstance(val, int):
dt = int
elif isinstance(val, float):
dt = float
elif isinstance(val, str):
dt = "S%s" % len(val)
dt = "U%s" % len(val)
else:
raise ValueError(
"Only support int, float, string currently, "
"Only support int, float, string, bool currently, "
"found %s" % type(d[key])
)

Expand Down
26 changes: 26 additions & 0 deletions esutil/tests/test_numpy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,29 @@ def test_match_scalar():
a2 = 4
m1, m2 = eu.numpy_util.match(a2, a1)
assert m1.size == 0 and m2.size == 0


def test_dict2array():
dct = {
'float': 3.5,
'bool': True,
'int': 55,
'str': 'stuff',
}

arr = eu.numpy_util.dict2array(dct)

assert set(dct.keys()) == set(arr.dtype.names)

for d in arr.dtype.descr:
name = d[0]
if name == 'float':
assert d[1][1:] == 'f8'
elif name == 'bool':
assert d[1][1:] == 'b1'
elif name == 'int':
assert d[1][1:] == 'i8'
elif name == 'str':
assert d[1][1] == 'U'

assert arr[name][0] == dct[name]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def build_extensions(self):

setup(
name="esutil",
version="0.6.16",
version="0.6.17",
author="Erin Scott Sheldon",
author_email="erin.sheldon@gmail.com",
classifiers=classifiers,
Expand Down
Loading