File: pycompat.py

package info (click to toggle)
python-xarray 0.16.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,568 kB
  • sloc: python: 60,570; makefile: 236; sh: 38
file content (41 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np

from .utils import is_duck_array

integer_types = (int, np.integer)

try:
    import dask.array
    from dask.base import is_dask_collection

    # solely for isinstance checks
    dask_array_type = (dask.array.Array,)

    def is_duck_dask_array(x):
        return is_duck_array(x) and is_dask_collection(x)


except ImportError:  # pragma: no cover
    dask_array_type = ()
    is_duck_dask_array = lambda _: False
    is_dask_collection = lambda _: False

try:
    # solely for isinstance checks
    import sparse

    sparse_array_type = (sparse.COO,)
except ImportError:  # pragma: no cover
    try:
        import scipy.sparse
        sparse_array_type = (scipy.sparse.coo_matrix,)
    except ImportError:  # pragma: no cover
        sparse_array_type = ()

try:
    # solely for isinstance checks
    import cupy

    cupy_array_type = (cupy.ndarray,)
except ImportError:  # pragma: no cover
    cupy_array_type = ()