From 93b02e5b9fbd1c4d310a21775fdbb6de6747cc01 Mon Sep 17 00:00:00 2001 From: pmla Date: Thu, 21 Jan 2021 21:43:25 +0100 Subject: [PATCH] BUG: maintain dtype of SphericalVoronoi regions --- scipy/spatial/_voronoi.pyx | 2 +- scipy/spatial/tests/test_spherical_voronoi.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scipy/spatial/_voronoi.pyx b/scipy/spatial/_voronoi.pyx index 6c24d8caea77..e6c09562a88b 100644 --- a/scipy/spatial/_voronoi.pyx +++ b/scipy/spatial/_voronoi.pyx @@ -75,4 +75,4 @@ def sort_vertices_of_regions(int[:,::1] simplices, regions): remaining_count += 1 remaining_filter(remaining, current_simplex) regions_arr = np.asarray(sorted_vertices) - regions[n] = regions_arr[regions_arr > ARRAY_FILLER].tolist() + regions[n] = list(regions_arr[regions_arr > ARRAY_FILLER]) diff --git a/scipy/spatial/tests/test_spherical_voronoi.py b/scipy/spatial/tests/test_spherical_voronoi.py index 3eee84accd47..07595073b1b4 100644 --- a/scipy/spatial/tests/test_spherical_voronoi.py +++ b/scipy/spatial/tests/test_spherical_voronoi.py @@ -347,3 +347,13 @@ def test_attribute_types(self, radius, center): assert sv.points.dtype is np.dtype(np.float64) assert sv.center.dtype is np.dtype(np.float64) assert isinstance(sv.radius, float) + + def test_region_types(self): + # Tests that region integer type does not change + # See Issue #13412 + sv = SphericalVoronoi(self.points) + dtype = type(sv.regions[0][0]) + sv.sort_vertices_of_regions() + assert type(sv.regions[0][0]) == dtype + sv.sort_vertices_of_regions() + assert type(sv.regions[0][0]) == dtype