Skip to content

Commit

Permalink
Merge pull request #261 from simonsobs/numpy-2p0-changes
Browse files Browse the repository at this point in the history
Fix numpy 2.0 errors
  • Loading branch information
JBorrow authored Jul 3, 2024
2 parents 6972ee7 + b5e7f8c commit 43e5b1d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pixell/enmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def __array_finalize__(self, obj):
def __repr__(self):
return "ndmap(%s,%s)" % (np.asarray(self), wcsutils.describe(self.wcs))
def __str__(self): return repr(self)
def __array_wrap__(self, arr, context=None):
def __array_wrap__(self, arr, context=None, return_scalar=False):
# In the future need to support `return_scalar`, but that is seemingly
# undocumented and not actually supported in numpy 2.0? So for now we
# just ignore it.
if arr.ndim < 2: return arr
return ndmap(arr, self.wcs)
def __reduce__(self):
Expand Down
8 changes: 8 additions & 0 deletions pixell/enplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ def draw_colorbar(crange, width, args):
fmt = "%g"
labels, boxes = [], []
for val in crange:
# Val could be a one-element array. In NumPy 1.25 this is not
# acceptable to string formatters.

try:
val = val[0]
except (TypeError, IndexError):
pass

Check warning on line 551 in pixell/enplot.py

View check run for this annotation

Codecov / codecov/patch

pixell/enplot.py#L550-L551

Added lines #L550 - L551 were not covered by tests

labels.append(fmt % val)
boxes.append(font.getbbox(labels[-1])[-2:])
boxes = np.array(boxes,int)
Expand Down
5 changes: 4 additions & 1 deletion pixell/tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def __array_finalize__(self, obj):
def __repr__(self):
return "TileMap(%s,%s)" % (np.asarray(self), str(self.geometry))
def __str__(self): return repr(self)
def __array_wrap__(self, arr, context=None):
def __array_wrap__(self, arr, context=None, return_scalar=False):
# In the future need to support `return_scalar`, but that is seemingly
# undocumented and not actually supported in numpy 2.0? So for now we
# just ignore it.
return TileMap(arr, self.geometry)
def __getitem__(self, sel):
# Split sel into normal and wcs parts.
Expand Down
4 changes: 0 additions & 4 deletions tests/test_pixell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,3 @@ def test_tilemap(self):
assert m1c.geometry.nactive == 2
assert np.allclose(m1c, 1)


if __name__ == '__main__':
unittest.main()
test_sim_slice()

0 comments on commit 43e5b1d

Please sign in to comment.