Skip to content

Commit

Permalink
Merge pull request #1485 from neutrinoceros/fix_numpy_bool
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke committed Jul 1, 2023
2 parents 7616e47 + 2ed3dcd commit 948bc2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Next Version
* remove unusable C-linkage with std::vector (#1468)
* fixed compatibility issue with Python 3.10 in endf.py (#1472)
* avoid use of deprecated numpy.int alias (#1479)
* avoid use of deprecated numpy.bool alias (#1485)

v0.7.7
======
Expand Down
23 changes: 12 additions & 11 deletions pyne/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
),
}

_INTEGRAL_TYPES = (int, np.integer, np.bool_)
_INTEGRAL_TYPES = (int, np.integer, bool, np.bool_)
_BOOLEAN_TYPES = (bool, np.bool_)
_SEQUENCE_TYPES = (Sequence, np.ndarray)


Expand Down Expand Up @@ -155,7 +156,7 @@ def __getitem__(self, key):
return getattr(mats[int(key)], name)
elif isinstance(key, slice):
return np.array([getattr(mats[i], name) for i in range(*key.indices(size))])
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length of the mesh.")
return np.array([getattr(mats[i], name) for i, b in enumerate(key) if b])
Expand All @@ -182,7 +183,7 @@ def __setitem__(self, key, value):
else:
for i in idx:
setattr(mats[i], name, value)
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match " "the length of the mesh.")
idx = np.where(key)[0]
Expand Down Expand Up @@ -234,7 +235,7 @@ def __getitem__(self, key):
return np.array(
[getattr(mats[i], name)() for i in range(*key.indices(size))]
)
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the " "length of the mesh.")
return np.array([getattr(mats[i], name)() for i, b in enumerate(key) if b])
Expand Down Expand Up @@ -278,7 +279,7 @@ def __getitem__(self, key):
return mats[key].metadata[name]
elif isinstance(key, slice):
return [mats[i].metadata[name] for i in range(*key.indices(size))]
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length " "of the mesh.")
return [mats[i].metadata[name] for i, b in enumerate(key) if b]
Expand All @@ -305,7 +306,7 @@ def __setitem__(self, key, value):
else:
for i in idx:
mats[i].metadata[name] = value
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length " "of the mesh.")
idx = np.where(key)[0]
Expand Down Expand Up @@ -338,7 +339,7 @@ def __delitem__(self, key):
elif isinstance(key, slice):
for i in range(*key.indices(size)):
del mats[i].metadata[name]
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length " "of the mesh.")
for i, b in enumerate(key):
Expand Down Expand Up @@ -495,7 +496,7 @@ def __getitem__(self, key):
ents = list(miter)[key]
data = self.mesh.mesh.tag_get_data(self.tag, ents, flat=flat)
return data
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length " "of the mesh.")
return self.mesh.mesh.tag_get_data(
Expand Down Expand Up @@ -542,7 +543,7 @@ def __setitem__(self, key, value):
v.shape = (len(key),)
v[...] = value
self.mesh.mesh.tag_set_data(mtag, key, v)
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != msize:
raise KeyError("boolean mask must match the length " "of the mesh.")
key = [ve for b, ve in zip(key, miter) if b]
Expand Down Expand Up @@ -584,7 +585,7 @@ def __delitem__(self, key):
self.mesh.mesh.tag_delete_data(mtag, i_ve[1])
elif isinstance(key, slice):
self.mesh.mesh.tag_delete_data(mtag, list(miter)[key])
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the " "length of the mesh.")
self.mesh.mesh.tag_delete_data(mtag, [ve for b, ve in zip(key, miter) if b])
Expand Down Expand Up @@ -754,7 +755,7 @@ def __getitem__(self, key):
return f(m, key)
elif isinstance(key, slice):
return [f(m, i) for i in range(*key.indices(size))]
elif isinstance(key, np.ndarray) and key.dtype == np.bool:
elif isinstance(key, np.ndarray) and key.dtype in _BOOLEAN_TYPES:
if len(key) != size:
raise KeyError("boolean mask must match the length " "of the mesh.")
return [f(m, i) for i, b in enumerate(key) if b]
Expand Down

0 comments on commit 948bc2b

Please sign in to comment.