Skip to content

Commit 0c30d41

Browse files
authored
gh-223: fixes for NumPy 2 (#224)
1 parent 60698b9 commit 0c30d41

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

heracles/healpy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def wrapper(*args):
4848
newargs = []
4949
for arr in args:
5050
if arr.dtype.byteorder != "=":
51-
arr = arr.newbyteorder("=").byteswap()
51+
arr = arr.view(arr.dtype.newbyteorder("=")).byteswap()
5252
newargs.append(arr)
5353
return fn(*newargs)
5454

heracles/io.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ def _write_map(fits, ext, key, m, *, names=None):
214214

215215
def _read_map(hdu):
216216
"""read HEALPix map from FITS table"""
217+
from numpy.lib.recfunctions import structured_to_unstructured
217218

218219
# read the map from the extension
219220
m = hdu.read()
220221

221222
# turn the structured array of columns into an unstructured array
222223
# transpose so that columns become rows (as that is how maps are)
223224
# then squeeze out degenerate axes
224-
m = np.squeeze(np.lib.recfunctions.structured_to_unstructured(m).T)
225+
m = np.squeeze(structured_to_unstructured(m).T)
225226

226227
# read and attach metadata
227228
m.dtype = np.dtype(m.dtype, metadata=_read_metadata(hdu))

heracles/result.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ def __array_finalize__(self, obj: NDArray[Any] | None) -> None:
7979
self.upper = getattr(obj, "upper", None)
8080
self.weight = getattr(obj, "weight", None)
8181

82-
def __array_wrap__(self, context=None, return_scalar=False):
83-
return super().__array_wrap__(context, return_scalar).view(np.ndarray)
82+
def __array_wrap__(self, arr, context=None, return_scalar=False):
83+
out = super().__array_wrap__(arr, context)
84+
if out is self or type(self) is not Result:
85+
return out
86+
if return_scalar:
87+
return out.item()
88+
return out.view(np.ndarray)
8489

8590

8691
def binned(result, bins, weight=None):

0 commit comments

Comments
 (0)