Skip to content

Commit

Permalink
Support NumPy 1.24+ (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow authored Jan 19, 2023
1 parent d416b69 commit 4dddd67
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- run:
name: run tests on latest numpy
command: |
pip install numpy==1.23.4
pip install numpy==1.24.1
./dev.py coverage
- store_artifacts:
Expand Down
2 changes: 1 addition & 1 deletion lacecore/_common/reindexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def indices_of_original_elements_after_applying_mask(mask):
produce an array containing the new indices of the original elements. Returns
-1 as the index of the removed elements.
"""
result = np.repeat(np.int(-1), len(mask))
result = np.repeat(-1, len(mask))
result[mask] = np.arange(np.count_nonzero(mask))
return result

Expand Down
4 changes: 2 additions & 2 deletions lacecore/_group_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, num_elements, group_names, masks, copy_masks=False):
if not all(isinstance(group_name, str) for group_name in group_names):
raise ValueError("group_names should be a list of strings")
vg.shape.check(locals(), "masks", (len(group_names), num_elements))
if masks.dtype != np.bool:
if masks.dtype != bool:
raise ValueError("Expected masks to be a bool array")

if copy_masks:
Expand All @@ -45,7 +45,7 @@ def from_dict(cls, group_data, num_elements):
group_data (dict): The group data.
num_elements (int): The total number of elements.
"""
masks = np.zeros((len(group_data), num_elements), dtype=np.bool)
masks = np.zeros((len(group_data), num_elements), dtype=bool)
for i, element_indices in enumerate(group_data.values()):
try:
masks[i][element_indices] = True
Expand Down
2 changes: 1 addition & 1 deletion lacecore/_obj/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def write(fp, mesh):
fp.write("v {} {} {}\n".format(*vertex))

face_groups = mesh.face_groups or GroupMap.from_dict({}, len(mesh.f))
last_group_mask = np.zeros(len(face_groups.keys()), dtype=np.bool)
last_group_mask = np.zeros(len(face_groups.keys()), dtype=bool)
for i, face in enumerate(mesh.f):
this_group_mask = face_groups.mask_for_element(i)
if np.any(last_group_mask != this_group_mask):
Expand Down
4 changes: 2 additions & 2 deletions lacecore/_selection/reconcile_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def reconcile_selection(faces, face_mask, vertex_mask, prune_orphan_vertices):
check_arity(faces)
vg.shape.check(locals(), "face_mask", (num_faces,))
num_vertices = vg.shape.check(locals(), "vertex_mask", (-1,))
if face_mask.dtype != np.bool or vertex_mask.dtype != np.bool:
if face_mask.dtype != bool or vertex_mask.dtype != bool:
raise ValueError("Expected face_mask and vertex_mask to be boolean arrays")
check_indices(faces, num_vertices, "faces")

# Invalidate faces containing any vertex which is being removed.
reconciled_face_mask = np.zeros_like(face_mask, dtype=np.bool)
reconciled_face_mask = np.zeros_like(face_mask, dtype=bool)
reconciled_face_mask[face_mask] = np.all(vertex_mask[faces[face_mask]], axis=1)

# Optionally, invalidate vertices for faces which are being removed.
Expand Down
8 changes: 4 additions & 4 deletions lacecore/_selection/selection_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(
):
self._target = target
self._union_with = union_with
self._vertex_mask = np.ones(target.num_v, dtype=np.bool)
self._face_mask = np.ones(target.num_f, dtype=np.bool)
self._vertex_mask = np.ones(target.num_v, dtype=bool)
self._face_mask = np.ones(target.num_f, dtype=bool)

def _keep_faces(self, mask):
self._face_mask = np.logical_and(self._face_mask, mask)
Expand Down Expand Up @@ -189,12 +189,12 @@ def vertices_behind_plane(self, plane):
@staticmethod
def _mask_like(value, num_elements):
value = np.asarray(value)
if value.dtype == np.bool:
if value.dtype == bool:
vg.shape.check(locals(), "value", (num_elements,))
return value
else:
check_indices(value, num_elements, "mask")
mask = np.zeros(num_elements, dtype=np.bool)
mask = np.zeros(num_elements, dtype=bool)
mask[value] = True
return mask

Expand Down
4 changes: 2 additions & 2 deletions lacecore/_selection/test_reconcile_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def test_reconcile_selection_validation():
reconcile_selection(
faces=example_mesh.f,
face_mask=np.zeros(example_mesh.num_f),
vertex_mask=np.zeros(example_mesh.num_v, dtype=np.bool),
vertex_mask=np.zeros(example_mesh.num_v, dtype=bool),
prune_orphan_vertices=False,
)
with pytest.raises(
ValueError, match="Expected face_mask and vertex_mask to be boolean arrays"
):
reconcile_selection(
faces=example_mesh.f,
face_mask=np.zeros(example_mesh.num_f, dtype=np.bool),
face_mask=np.zeros(example_mesh.num_f, dtype=bool),
vertex_mask=np.zeros(example_mesh.num_v),
prune_orphan_vertices=False,
)
2 changes: 1 addition & 1 deletion lacecore/_selection/test_selection_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_pick_vertices_list():


def test_pick_vertices_mask():
wanted_v_mask = np.zeros(8, dtype=np.bool)
wanted_v_mask = np.zeros(8, dtype=bool)
wanted_v_mask[[3, 7, 4]] = True
submesh = cube_at_origin.picking_vertices(wanted_v_mask)

Expand Down
12 changes: 6 additions & 6 deletions lacecore/test_group_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_group_map_indices_out_of_range():


def test_group_map_with_copy_true_makes_readonly_copy():
masks = np.zeros((3, 12), dtype=np.bool)
masks = np.zeros((3, 12), dtype=bool)
groups = GroupMap(
num_elements=12, group_names=["a", "b", "c"], masks=masks, copy_masks=True
)
Expand All @@ -121,7 +121,7 @@ def test_group_map_with_copy_true_makes_readonly_copy():


def test_group_map_with_copy_false_makes_read_only():
masks = np.zeros((3, 12), dtype=np.bool)
masks = np.zeros((3, 12), dtype=bool)
GroupMap(
num_elements=12, group_names=["a", "b", "c"], masks=masks, copy_masks=False
)
Expand All @@ -136,15 +136,15 @@ def test_invalid_num_elements_throws_error():
GroupMap(
num_elements=-1,
group_names=["a", "b", "c"],
masks=np.zeros((3, 12), dtype=np.bool),
masks=np.zeros((3, 12), dtype=bool),
)
with pytest.raises(
ValueError, match="num_elements should be a non-negative integer"
):
GroupMap(
num_elements="foo",
group_names=["a", "b", "c"],
masks=np.zeros((3, 12), dtype=np.bool),
masks=np.zeros((3, 12), dtype=bool),
)


Expand All @@ -153,7 +153,7 @@ def test_invalid_group_name_throws_error():
GroupMap(
num_elements=12,
group_names=[1, 2, 3],
masks=np.zeros((3, 12), dtype=np.bool),
masks=np.zeros((3, 12), dtype=bool),
)


Expand All @@ -162,7 +162,7 @@ def test_invalid_mask_throws_error():
GroupMap(
num_elements=12,
group_names=["a", "b", "c"],
masks=np.zeros((3, 12), dtype=np.int),
masks=np.zeros((3, 12), dtype=int),
)


Expand Down

0 comments on commit 4dddd67

Please sign in to comment.