Repository: pydata/sparse
Pull request #641 (2024-02-07 12:41:03)

Modernize CI

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pydata/sparse/pull/641?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydata) Report
> Merging [#641](https://app.codecov.io/gh/pydata/sparse/pull/641?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydata) (82db3e5) into [main](https://app.codecov.io/gh/pydata/sparse/commit/f37d9beebfc2f99d91758d5662fc3e6ec5e6e816?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydata) (f37d9be) will **increase** coverage by `0.04%`.
> The diff coverage is `n/a`.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #641      +/-   ##
==========================================
+ Coverage   90.22%   90.27%   +0.04%     
==========================================
  Files          20       20              
  Lines        3674     3672       -2     
==========================================
  Hits         3315     3315              
+ Misses        359      357       -2     
```



</details>

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e7619da..fa63c2d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -23,9 +23,9 @@ jobs:
       NUMBA_BOUNDSCHECK: ${{ matrix.numba_boundscheck }}
     steps:
       - name: Checkout Repo
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Cache conda
-        uses: actions/cache@v3
+        uses: actions/cache@v4
         env:
           # Increase this value to reset cache if ci/environment.yml has not changed
           CACHE_NUMBER: 0
@@ -34,25 +34,23 @@ jobs:
           key:
             test-${{ matrix.os }}-conda-py${{ matrix.python }}-${{ env.CACHE_NUMBER }}-${{
             hashFiles('ci/environment.yml') }}
-      - uses: conda-incubator/setup-miniconda@v2
+      - uses: conda-incubator/setup-miniconda@v3
         with:
           activate-environment: sparse-dev
           allow-softlinks: true
           environment-file: ci/environment.yml
           python-version: ${{ matrix.python }}
-          miniforge-variant: Mambaforge
-          use-only-tar-bz2: true
-          use-mamba: true
+          miniforge-version: latest
       - name: Install package
         run: |
           pip install -e .[tests]
       - name: Run tests
         run: |
           pytest --pyargs sparse
-      - uses: codecov/codecov-action@v3
+      - uses: codecov/codecov-action@v4
         if: always()
-      - name: Publish Unit Test Results
-        uses: EnricoMi/publish-unit-test-result-action/composite@v1
+      - name: Publish Test Results
+        uses: EnricoMi/publish-unit-test-result-action/composite@v2
         if: always()
         with:
           files: "**/test-*.xml"
@@ -63,9 +61,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout Repo
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Cache conda
-        uses: actions/cache@v3
+        uses: actions/cache@v4
         env:
           # Increase this value to reset cache if ci/environment.yml has not changed
           CACHE_NUMBER: 0
@@ -80,15 +78,13 @@ jobs:
           environment-file: ci/environment.yml
           python-version: '3.10'
           miniforge-version: latest
-          use-only-tar-bz2: true
-          use-mamba: true
       - name: Install package
         run: |
           pip install -e .[docs]
       - name: Run tests
         run: |
           sphinx-build -W -b html docs/ _build/html
-      - uses: actions/upload-artifact@v1
+      - uses: actions/upload-artifact@v4
         with:
           name: Documentation
           path: _build/html
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
deleted file mode 100644
index be8aadd..0000000
--- a/.github/workflows/codeql.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-name: "CodeQL"
-
-on:
-  push:
-    branches: [ "main" ]
-  pull_request:
-    branches: [ "main" ]
-  schedule:
-    - cron: "51 22 * * 6"
-
-jobs:
-  analyze:
-    name: Analyze
-    runs-on: ubuntu-latest
-    permissions:
-      actions: read
-      contents: read
-      security-events: write
-
-    strategy:
-      fail-fast: false
-      matrix:
-        language: [ python ]
-
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v3
-
-      - name: Initialize CodeQL
-        uses: github/codeql-action/init@v2
-        with:
-          languages: ${{ matrix.language }}
-          queries: +security-and-quality
-
-      - name: Autobuild
-        uses: github/codeql-action/autobuild@v2
-
-      - name: Perform CodeQL Analysis
-        uses: github/codeql-action/analyze@v2
-        with:
-          category: "/language:${{ matrix.language }}"
diff --git a/sparse/__init__.py b/sparse/__init__.py
index c56e347..7050edf 100644
--- a/sparse/__init__.py
+++ b/sparse/__init__.py
@@ -23,6 +23,7 @@ from numpy import (
     greater,
     greater_equal,
     iinfo,
+    imag,
     inf,
     int8,
     int16,
@@ -46,6 +47,7 @@ from numpy import (
     not_equal,
     pi,
     positive,
+    real,
     remainder,
     sign,
     sin,
@@ -228,6 +230,7 @@ __all__ = [
     "greater",
     "greater_equal",
     "iinfo",
+    "imag",
     "inf",
     "int16",
     "int32",
@@ -279,6 +282,7 @@ __all__ = [
     "pow",
     "prod",
     "random",
+    "real",
     "remainder",
     "reshape",
     "result_type",
diff --git a/sparse/_sparse_array.py b/sparse/_sparse_array.py
index c5cadcf..3a954ab 100644
--- a/sparse/_sparse_array.py
+++ b/sparse/_sparse_array.py
@@ -172,7 +172,7 @@ class SparseArray:
             from matrepr.adapters.sparse_driver import PyDataSparseDriver
 
             return to_html(PyDataSparseDriver.adapt(self), notebook=True)
-        except ImportError:
+        except (ImportError, ValueError):
             return html_table(self)
 
     def _str_impl(self, summary):
@@ -203,7 +203,7 @@ class SparseArray:
                 max_cols=9999,
             )
             return f"{summary}\n{values}"
-        except ImportError:
+        except (ImportError, ValueError):
             return summary
 
     @abstractmethod
diff --git a/sparse/_utils.py b/sparse/_utils.py
index 28f339b..50089aa 100644
--- a/sparse/_utils.py
+++ b/sparse/_utils.py
@@ -1,5 +1,6 @@
 import functools
 import operator
+import warnings
 from collections.abc import Iterable
 from functools import reduce
 from numbers import Integral
@@ -616,11 +617,17 @@ def get_out_dtype(arr, scalar):
 
 
 def can_store(dtype, scalar):
-    return np.array(scalar, dtype=dtype) == np.array(scalar)
+    try:
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            warnings.filterwarnings("error", "out-of-bound", DeprecationWarning)
+            return np.array(scalar, dtype=dtype) == np.array(scalar)
+    except ValueError:
+        return False
 
 
 def is_unsigned_dtype(dtype):
-    return np.array(-1, dtype=dtype) != np.array(-1)
+    return np.issubdtype(dtype, np.integer) and np.iinfo(dtype).min == 0
 
 
 def convert_format(format):


Test patch:
diff --git a/sparse/tests/test_namespace.py b/sparse/tests/test_namespace.py
index 4df2b9e..902b1ff 100644
--- a/sparse/tests/test_namespace.py
+++ b/sparse/tests/test_namespace.py
@@ -71,6 +71,7 @@ def test_namespace():
         "greater",
         "greater_equal",
         "iinfo",
+        "imag",
         "inf",
         "int16",
         "int32",
@@ -122,6 +123,7 @@ def test_namespace():
         "pow",
         "prod",
         "random",
+        "real",
         "remainder",
         "reshape",
         "result_type",