From: =?utf-8?q?Brigitta_Sip=C5=91cz?= <bsipocz@gmail.com>
Date: Tue, 20 Dec 2022 05:34:03 -0800
Subject: [PATCH] MAINT: fix for np 1.24 (#858)

* CI: update actions versions

* CI: do only weekly cron

* MAINT: tox4 compatibility fixes

* MAINT: temporarily limit numpy version

* CI: update codecov action version, too

* MAINT: fix compatibility with np 1.24

* MAINT: remove version pin

* MAINT: remove travis CI things
---
 .github/workflows/publish.yml             |  8 ++++----
 spectral_cube/_moments.py                 |  2 +-
 spectral_cube/dask_spectral_cube.py       |  2 +-
 spectral_cube/spectral_cube.py            |  8 ++++----
 spectral_cube/tests/test_moments.py       |  2 +-
 spectral_cube/tests/test_spectral_cube.py | 15 +++------------
 6 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 708072b..3777b04 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -7,8 +7,8 @@ jobs:
     name: Build source distribution
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v2
-      - uses: actions/setup-python@v2
+      - uses: actions/checkout@v3
+      - uses: actions/setup-python@v4
         name: Install Python
         with:
           python-version: '3.9'
@@ -16,7 +16,7 @@ jobs:
         run: python -m pip install build
       - name: Build sdist
         run: python -m build --sdist --wheel --outdir dist/ .
-      - uses: actions/upload-artifact@v2
+      - uses: actions/upload-artifact@v3
         with:
           path: dist/*
 
@@ -26,7 +26,7 @@ jobs:
     runs-on: ubuntu-latest
     if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
     steps:
-      - uses: actions/download-artifact@v2
+      - uses: actions/download-artifact@v3
         with:
           name: artifact
           path: dist
diff --git a/spectral_cube/_moments.py b/spectral_cube/_moments.py
index 04ea68c..b19bcbd 100644
--- a/spectral_cube/_moments.py
+++ b/spectral_cube/_moments.py
@@ -46,7 +46,7 @@ def _slice0(cube, axis):
 
     view = [slice(None)] * 3
 
-    valid = np.zeros(shp, dtype=np.bool)
+    valid = np.zeros(shp, dtype=bool)
     for i in range(cube.shape[axis]):
         view[axis] = i
         plane = cube._get_filled_data(fill=np.nan, view=tuple(view))
diff --git a/spectral_cube/dask_spectral_cube.py b/spectral_cube/dask_spectral_cube.py
index e4121f6..d13c1f8 100644
--- a/spectral_cube/dask_spectral_cube.py
+++ b/spectral_cube/dask_spectral_cube.py
@@ -1528,7 +1528,7 @@ class DaskVaryingResolutionSpectralCube(DaskSpectralCubeMixin, VaryingResolution
 
         # We need to pass in the beams to dask, so we hide them inside an object array
         # that can then be chunked like the data.
-        beams = da.from_array(np.array(beams, dtype=np.object)
+        beams = da.from_array(np.array(beams, dtype=object)
                               .reshape((len(beams), 1, 1)), chunks=(-1, -1, -1))
 
         needs_beam_ratio = self.unit.is_equivalent(u.Jy / u.beam)
diff --git a/spectral_cube/spectral_cube.py b/spectral_cube/spectral_cube.py
index 2efbe3c..7544e38 100644
--- a/spectral_cube/spectral_cube.py
+++ b/spectral_cube/spectral_cube.py
@@ -2787,7 +2787,7 @@ class BaseSpectralCube(BaseNDClass, MaskableArrayMixinClass,
 
         if use_memmap:
             ntf = tempfile.NamedTemporaryFile(dir=memmap_dir)
-            outcube = np.memmap(ntf, mode='w+', shape=self.shape, dtype=np.float)
+            outcube = np.memmap(ntf, mode='w+', shape=self.shape, dtype=float)
         else:
             if self._is_huge and not self.allow_huge_operations:
                 raise ValueError("Applying a function without ``use_memmap`` "
@@ -2797,7 +2797,7 @@ class BaseSpectralCube(BaseNDClass, MaskableArrayMixinClass,
                                  "set ``use_memmap=True`` or set "
                                  "``cube.allow_huge_operations=True`` to "
                                  "override this restriction.")
-            outcube = np.empty(shape=self.shape, dtype=np.float)
+            outcube = np.empty(shape=self.shape, dtype=float)
 
         if num_cores == 1 and parallel:
             warnings.warn("parallel=True was specified but num_cores=1. "
@@ -3352,9 +3352,9 @@ class BaseSpectralCube(BaseNDClass, MaskableArrayMixinClass,
             view_newaxis = tuple(view_newaxis)
 
             ntf = tempfile.NamedTemporaryFile()
-            dsarr = np.memmap(ntf, mode='w+', shape=newshape, dtype=np.float)
+            dsarr = np.memmap(ntf, mode='w+', shape=newshape, dtype=float)
             ntf2 = tempfile.NamedTemporaryFile()
-            mask = np.memmap(ntf2, mode='w+', shape=newshape, dtype=np.bool)
+            mask = np.memmap(ntf2, mode='w+', shape=newshape, dtype=bool)
             for ii in progressbar(range(newshape[axis])):
                 view_fulldata = makeslice_local(ii*factor)
                 view_newdata = makeslice_local(ii, nsteps=1)
diff --git a/spectral_cube/tests/test_moments.py b/spectral_cube/tests/test_moments.py
index 4feb67d..3043dd5 100644
--- a/spectral_cube/tests/test_moments.py
+++ b/spectral_cube/tests/test_moments.py
@@ -58,7 +58,7 @@ MOMENTSu = MOMENTS
 
 
 def moment_cube():
-    cube = np.arange(27).reshape([3, 3, 3]).astype(np.float)
+    cube = np.arange(27).reshape([3, 3, 3]).astype(float)
     wcs = WCS(naxis=3)
     wcs.wcs.ctype = ['RA---TAN', 'DEC--TAN', 'VELO']
     # choose values to minimize spherical distortions
diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py
index 0057a6f..6ce7f4e 100644
--- a/spectral_cube/tests/test_spectral_cube.py
+++ b/spectral_cube/tests/test_spectral_cube.py
@@ -76,8 +76,6 @@ except ImportError:
     scipyOK = False
 
 import os
-# if ON_TRAVIS is set, we're on travis.
-on_travis = bool(os.environ.get('ON_TRAVIS'))
 
 from radio_beam import Beam, Beams
 from radio_beam.utils import BeamError
@@ -637,14 +635,7 @@ class TestNumpyMethods(BaseTest):
         # regular median.
 
         scmed = self.c.apply_numpy_function(np.median, axis=0)
-        # this checks whether numpy <=1.9.3 has a bug?
-        # as far as I can tell, np==1.9.3 no longer has this bug/feature
-        #if LooseVersion(np.__version__) <= LooseVersion('1.9.3'):
-        #    # print statements added so we get more info in the travis builds
-        #    print("Numpy version is: {0}".format(LooseVersion(np.__version__)))
-        #    assert np.count_nonzero(np.isnan(scmed)) == 5
-        #else:
-        #    print("Numpy version is: {0}".format(LooseVersion(np.__version__)))
+
         assert np.count_nonzero(np.isnan(scmed)) == 6
 
         scmed = self.c.apply_numpy_function(np.nanmedian, axis=0)
@@ -991,7 +982,7 @@ def test_with_mask_with_boolean_array(use_dask):
 
 def test_with_mask_with_good_array_shape(use_dask):
     cube = _dummy_cube(use_dask)
-    mask = np.zeros((1, 5), dtype=np.bool)
+    mask = np.zeros((1, 5), dtype=bool)
     cube2 = cube.with_mask(mask, inherit_mask=False)
     assert isinstance(cube2._mask, BooleanArrayMask)
     np.testing.assert_equal(cube2._mask._mask, mask.reshape((1, 1, 5)))
@@ -999,7 +990,7 @@ def test_with_mask_with_good_array_shape(use_dask):
 
 def test_with_mask_with_bad_array_shape(use_dask):
     cube = _dummy_cube(use_dask)
-    mask = np.zeros((5, 5), dtype=np.bool)
+    mask = np.zeros((5, 5), dtype=bool)
     with pytest.raises(ValueError) as exc:
         cube.with_mask(mask)
     assert exc.value.args[0] == ("Mask shape is not broadcastable to data shape: "
