Skip to content

Commit

Permalink
remove reference to array_api
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Aug 28, 2024
1 parent 68f76ff commit ce64bac
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 98 deletions.
1 change: 0 additions & 1 deletion arkouda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
del get_versions

from arkouda.numpy import *
from arkouda.array_api import *
from arkouda.array_view import *
from arkouda.client import *
from arkouda.client_dtypes import *
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
import warnings

from .array_object import Array
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/_typing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
"""
This file defines the types for type annotations.
Expand Down
61 changes: 37 additions & 24 deletions arkouda/array_api/array_object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
"""
Wrapper class around the ndarray object for the array API standard.
Expand All @@ -16,26 +15,30 @@

from __future__ import annotations

import types
from enum import IntEnum
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union

from ._dtypes import ( # _all_dtypes,; _integer_or_boolean_dtypes,; _numeric_dtypes,
from ._dtypes import (
# _all_dtypes,
_boolean_dtypes,
_complex_floating_dtypes,
_dtype_categories,
_floating_dtypes,
_integer_dtypes,
# _integer_or_boolean_dtypes,
_floating_dtypes,
_complex_floating_dtypes,
# _numeric_dtypes,
_result_type,
_dtype_categories,
)
from .creation_functions import asarray

from typing import TYPE_CHECKING, Optional, Tuple, Union, Any, Dict, Callable, List
import types

if TYPE_CHECKING:
from ._typing import Device, Dtype

import arkouda as ak
import numpy as np

import arkouda as ak
from arkouda.pdarraycreation import scalar_array
from arkouda import array_api

HANDLED_FUNCTIONS: Dict[str, Callable] = {}
Expand Down Expand Up @@ -119,7 +122,9 @@ def item(self):
if self._has_single_elem():
return self._array[0]
else:
raise ValueError("Can only convert an array with one element to a Python scalar")
raise ValueError(
"Can only convert an array with one element to a Python scalar"
)

def transpose(self, axes: Optional[Tuple[int, ...]] = None):
"""
Expand Down Expand Up @@ -183,7 +188,9 @@ def chunk_info(self: Array, /) -> List[List[int]]:
"""
import json

return json.loads(ak.generic_msg(cmd=f"chunkInfo{self.ndim}D", args={"array": self._array}))
return json.loads(
ak.generic_msg(cmd=f"chunkInfo{self.ndim}D", args={"array": self._array})
)

def __array__(self, dtype: None | np.dtype[Any] = None):
"""
Expand Down Expand Up @@ -237,7 +244,9 @@ def _check_allowed_dtypes(

# The spec explicitly disallows this.
if res_dtype != self.dtype:
raise TypeError(f"Cannot perform {op} with dtypes {self.dtype} and {other.dtype}")
raise TypeError(
f"Cannot perform {op} with dtypes {self.dtype} and {other.dtype}"
)

return other

Expand All @@ -255,10 +264,14 @@ def _promote_scalar(self, scalar) -> Array:
# allowed.
if isinstance(scalar, bool):
if self.dtype not in _boolean_dtypes:
raise TypeError("Python bool scalars can only be promoted with bool arrays")
raise TypeError(
"Python bool scalars can only be promoted with bool arrays"
)
elif isinstance(scalar, int):
if self.dtype in _boolean_dtypes:
raise TypeError("Python int scalars cannot be promoted with bool arrays")
raise TypeError(
"Python int scalars cannot be promoted with bool arrays"
)
if self.dtype in _integer_dtypes:
info = np.iinfo(int)
if not (info.min <= scalar <= info.max):
Expand All @@ -268,7 +281,9 @@ def _promote_scalar(self, scalar) -> Array:
# int + array(floating) is allowed
elif isinstance(scalar, float):
if self.dtype not in _floating_dtypes:
raise TypeError("Python float scalars can only be promoted with floating-point arrays.")
raise TypeError(
"Python float scalars can only be promoted with floating-point arrays."
)
elif isinstance(scalar, complex):
if self.dtype not in _complex_floating_dtypes:
raise TypeError(
Expand Down Expand Up @@ -350,7 +365,9 @@ def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
else:
return Array._new(self._array and other._array)

def __array_namespace__(self: Array, /, *, api_version: Optional[str] = None) -> types.ModuleType:
def __array_namespace__(
self: Array, /, *, api_version: Optional[str] = None
) -> types.ModuleType:
"""
Get the array API namespace from an `Array` instance.
"""
Expand Down Expand Up @@ -392,8 +409,6 @@ def __eq__(self: Array, other: object, /) -> bool:
"""
Check if this array is equal to another array or scalar.
"""
from arkouda.pdarraycreation import scalar_array

if isinstance(other, (int, bool, float)):
return self._array == scalar_array(other)
elif isinstance(other, Array):
Expand Down Expand Up @@ -436,8 +451,6 @@ def __getitem__(
key: Union[int, slice, Tuple[Union[int, slice], ...], Array],
/,
) -> Array:
from arkouda.pdarraycreation import scalar_array

if isinstance(key, Array):
if key.size == 1 or key.shape == ():
k = key._array[0]
Expand Down Expand Up @@ -496,7 +509,9 @@ def __index__(self: Array, /) -> int:
if isinstance(s, int):
return s
else:
raise TypeError("Only integer arrays can be converted to a Python integer")
raise TypeError(
"Only integer arrays can be converted to a Python integer"
)
else:
raise ValueError("cannot convert non-scalar array to int")

Expand Down Expand Up @@ -566,8 +581,6 @@ def __ne__(self: Array, other: object, /) -> bool:
"""
Check if this array is not equal to another array or scalar.
"""
from arkouda.pdarraycreation import scalar_array

if isinstance(other, (int, bool, float)):
return self._array != scalar_array(other)
elif isinstance(other, Array):
Expand Down Expand Up @@ -929,7 +942,7 @@ def _has_single_elem(self: Array, /) -> bool:
def _single_elem(self: Array) -> Optional[Union[int, float, complex, bool]]:
if self._has_single_elem():
if self.ndim > 0:
return self._array[(0,) * self.ndim]
return self._array[(0,)*self.ndim]
else:
return self._array[0]
else:
Expand Down
27 changes: 15 additions & 12 deletions arkouda/array_api/creation_functions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# type: ignore
from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, Tuple, Union, cast

import numpy as np

from arkouda.client import generic_msg
import numpy as np
from arkouda.pdarrayclass import create_pdarray, pdarray, _to_pdarray
from arkouda.pdarraycreation import scalar_array
from arkouda.numpy.dtypes import dtype as akdtype
from arkouda.numpy.dtypes import resolve_scalar_dtype
from arkouda.pdarrayclass import _to_pdarray, create_pdarray, pdarray

if TYPE_CHECKING:
from ._typing import (
Expand All @@ -18,8 +17,6 @@
NestedSequence,
SupportsBufferProtocol,
)


import arkouda as ak


Expand Down Expand Up @@ -86,7 +83,9 @@ def asarray(
elif isinstance(obj, np.ndarray):
return Array._new(_to_pdarray(obj, dt=dtype))
else:
raise ValueError("asarray not implemented for 'NestedSequence' or 'SupportsBufferProtocol'")
raise ValueError(
"asarray not implemented for 'NestedSequence' or 'SupportsBufferProtocol'"
)


def arange(
Expand Down Expand Up @@ -156,7 +155,9 @@ def empty(
)


def empty_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
def empty_like(
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
) -> Array:
"""
Return a new array whose shape and dtype match the input array, without initializing entries.
"""
Expand Down Expand Up @@ -311,7 +312,9 @@ def ones(
return a


def ones_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
def ones_like(
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
) -> Array:
"""
Return a new array whose shape and dtype match the input array, filled with ones.
"""
Expand Down Expand Up @@ -364,8 +367,6 @@ def zeros(
"""
Return a new array with the specified shape and type, filled with zeros.
"""
from arkouda.pdarraycreation import scalar_array

from .array_object import Array

if device not in ["cpu", None]:
Expand Down Expand Up @@ -393,7 +394,9 @@ def zeros(
return Array._new(create_pdarray(repMsg))


def zeros_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
def zeros_like(
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
) -> Array:
"""
Return a new array whose shape and dtype match the input array, filled with zeros.
"""
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/data_type_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array, implements_numpy
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/elementwise_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from ._dtypes import (
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/indexing_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/linalg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from .array_object import Array

from arkouda.client import generic_msg
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/manipulation_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array, implements_numpy
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/searching_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/set_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/sorting_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from .array_object import Array
Expand Down
1 change: 0 additions & 1 deletion arkouda/array_api/statistical_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# type: ignore
from __future__ import annotations

from typing import TYPE_CHECKING, Optional, Tuple, Union
Expand Down
11 changes: 5 additions & 6 deletions arkouda/array_api/utility_functions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# type: ignore
from __future__ import annotations

from .array_object import Array
from .manipulation_functions import concat

from typing import Optional, Tuple, Union

import arkouda as ak
from arkouda.pdarraycreation import scalar_array
from arkouda.client import generic_msg
from arkouda.pdarrayclass import create_pdarray
from arkouda.pdarraycreation import scalar_array

from .array_object import Array
from .manipulation_functions import concat
import arkouda as ak


def all(
Expand Down
Loading

0 comments on commit ce64bac

Please sign in to comment.