Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #4098: upgrade to numpy 2.0.0 #4099

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arkouda-env-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ channels:
- defaults
dependencies:
- python>=3.9,<3.12.4 # minimum 3.9
- numpy>=1.24.1,<2.0
# - numpy>=1.24.1,<2.0
- numpy>=2.0
- pandas>=1.4.0,!=2.2.0
- pyzmq>=20.0.0
- tabulate
Expand Down
17 changes: 0 additions & 17 deletions arkouda/numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# flake8: noqa
from numpy import ( # noqa
NAN,
NINF,
NZERO,
PINF,
PZERO,
DataSource,
False_,
Inf,
Infinity,
NaN,
ScalarType,
True_,
base_repr,
binary_repr,
byte,
bytes_,
cdouble,
cfloat,
clongdouble,
clongfloat,
compat,
csingle,
datetime64,
Expand All @@ -28,30 +17,24 @@
euler_gamma,
finfo,
flexible,
float_,
floating,
format_float_positional,
format_float_scientific,
half,
iinfo,
inexact,
inf,
infty,
intc,
intp,
isscalar,
issctype,
issubdtype,
longdouble,
longfloat,
longlong,
maximum_sctype,
nan,
number,
pi,
promote_types,
sctypeDict,
sctypes,
short,
signedinteger,
single,
Expand Down
16 changes: 16 additions & 0 deletions arkouda/numpy/_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ def _merge_where(new_pda, where, ret):
return new_pda


def can_cast(from_, to) -> ak_bool:
from arkouda.util import is_int
from arkouda.numpy.dtypes import uint64 as ak_unit64
from arkouda.numpy.dtypes import _is_dtype_in_union
from arkouda.numpy.dtypes import isSupportedInt

if (np.isscalar(from_) or _is_dtype_in_union(from_, numeric_scalars)) and not isinstance(
from_, (int, float, complex)
):
return np.can_cast(from_, to)
elif isSupportedInt(from_) and from_ >= 0 and to == ak_uint64:
return True

return False


@typechecked
def cast(
pda: Union[pdarray, Strings, Categorical], # type: ignore
Expand Down
29 changes: 24 additions & 5 deletions arkouda/numpy/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,25 @@ def __repr__(self) -> str:
# missing full support for: float32, int32, int16, int8, uint32, uint16, complex64, complex128
# ARKOUDA_SUPPORTED_DTYPES = frozenset([member.value for _, member in DType.__members__.items()])
ARKOUDA_SUPPORTED_DTYPES = frozenset(
["bool_", "float", "float64", "int", "int64", "uint", "uint64", "uint8", "bigint", "str"]
[
"bool_",
"float",
"float64",
"int",
"int64",
"uint",
"uint64",
"uint8",
"bigint",
"str",
]
)

DTypes = frozenset([member.value for _, member in DType.__members__.items()])
DTypeObjects = frozenset([bool_, float, float64, int, int64, str, str_, uint8, uint64])
NumericDTypes = frozenset(["bool_", "bool", "float", "float64", "int", "int64", "uint64", "bigint"])
NumericDTypes = frozenset(
["bool_", "bool", "float", "float64", "int", "int64", "uint64", "bigint"]
)
SeriesDTypes = {
"string": np.str_,
"<class 'str'>": np.str_,
Expand Down Expand Up @@ -337,7 +350,9 @@ def resolve_scalar_dtype(val: object) -> str:
):
return "bool"
# Python int or np.int* or np.uint*
elif isinstance(val, int) or (hasattr(val, "dtype") and cast(np.uint, val).dtype.kind in "ui"):
elif isinstance(val, int) or (
hasattr(val, "dtype") and cast(np.uint, val).dtype.kind in "ui"
):
# we've established these are int, uint, or bigint,
# so we can do comparisons
if isSupportedInt(val) and val >= 2**64: # type: ignore
Expand All @@ -347,9 +362,13 @@ def resolve_scalar_dtype(val: object) -> str:
else:
return "int64"
# Python float or np.float*
elif isinstance(val, float) or (hasattr(val, "dtype") and cast(np.float_, val).dtype.kind == "f"):
elif isinstance(val, float) or (
hasattr(val, "dtype") and cast(np.float64, val).dtype.kind == "f"
):
return "float64"
elif isinstance(val, complex) or (hasattr(val, "dtype") and cast(np.float_, val).dtype.kind == "c"):
elif isinstance(val, complex) or (
hasattr(val, "dtype") and cast(np.float64, val).dtype.kind == "c"
):
return "float64" # TODO: actually support complex values in the backend
elif isinstance(val, builtins.str) or isinstance(val, np.str_):
return "str"
Expand Down
4 changes: 2 additions & 2 deletions arkouda/numpy/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from numpy import RankWarning, TooHardError
# from numpy import RankWarning, TooHardError

__all__ = ["RankWarning", "TooHardError"]
# __all__ = ["RankWarning", "TooHardError"]
28 changes: 14 additions & 14 deletions arkouda/numpy/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# flake8: noqa
from numpy import (
RankWarning,
add_docstring,
add_newdoc,
deprecate,
deprecate_with_doc,
disp,
issubclass_,
# RankWarning,
# add_docstring,
# add_newdoc,
# deprecate,
# deprecate_with_doc,
# disp,
# issubclass_,
issubdtype,
polynomial,
typename,
Expand All @@ -16,14 +16,14 @@
from arkouda.numpy.lib.emath import *

__all__ = [
"RankWarning",
"add_docstring",
"add_newdoc",
"deprecate",
"deprecate_with_doc",
"disp",
# "RankWarning",
# "add_docstring",
# "add_newdoc",
# "deprecate",
# "deprecate_with_doc",
# "disp",
"emath",
"issubclass_",
# "issubclass_",
"issubdtype",
"polynomial",
"typename",
Expand Down
6 changes: 3 additions & 3 deletions arkouda/numpy/rec/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from numpy import format_parser

__all__ = ["format_parser"]
# from numpy import format_parser
#
# __all__ = ["format_parser"]
42 changes: 28 additions & 14 deletions arkouda/pdarrayclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,24 @@ def _binop(self, other: pdarray, op: str) -> pdarray:
# pdarray binop scalar
# If scalar cannot be safely cast, server will infer the return dtype
dt = resolve_scalar_dtype(other)
if self.dtype != bigint and np.can_cast(other, self.dtype):

from arkouda.numpy._numeric import can_cast as ak_can_cast

print("\n**\ndt: ", dt)
print("other: ", other)
print("self.dtype: ", self.dtype)
print(
"ak_can_cast(other, self.dtype): ",
ak_can_cast(other, self.dtype),
)

if self.dtype != bigint and ak_can_cast(other, self.dtype):
# If scalar can be losslessly cast to array dtype,
# do the cast so that return array will have same dtype
dt = self.dtype.name
other = self.dtype.type(other)
print("new dt: ", dt)
print("neow other: ", other)
if dt not in DTypes:
raise TypeError(f"Unhandled scalar type: {other} ({type(other)})")
repMsg = generic_msg(
Expand Down Expand Up @@ -616,7 +629,9 @@ def _r_binop(self, other: pdarray, op: str) -> pdarray:
# pdarray binop scalar
# If scalar cannot be safely cast, server will infer the return dtype
dt = resolve_scalar_dtype(other)
if self.dtype != bigint and np.can_cast(other, self.dtype):
from arkouda.numpy._numeric import can_cast as ak_can_cast

if self.dtype != bigint and ak_can_cast(other, self.dtype):
# If scalar can be losslessly cast to array dtype,
# do the cast so that return array will have same dtype
dt = self.dtype.name
Expand Down Expand Up @@ -4131,31 +4146,30 @@ def fmod(dividend: Union[pdarray, numeric_scalars], divisor: Union[pdarray, nume
)
# TODO: handle shape broadcasting for multidimensional arrays

# The code below creates a command string for fmod2vv, fmod2vs or fmod2sv.

# The code below creates a command string for fmod2vv, fmod2vs or fmod2sv.

if isinstance(dividend, pdarray) and isinstance(divisor, pdarray) :
if isinstance(dividend, pdarray) and isinstance(divisor, pdarray):
cmdstring = f"fmod2vv<{dividend.dtype},{dividend.ndim},{divisor.dtype}>"

elif isinstance(dividend, pdarray) and not (isinstance(divisor, pdarray)) :
if resolve_scalar_dtype(divisor) in ['float64', 'int64', 'uint64', 'bool'] :
acmd = 'fmod2vs_'+resolve_scalar_dtype(divisor)
else : # this condition *should* be impossible because of the isSupportedNumber check
elif isinstance(dividend, pdarray) and not (isinstance(divisor, pdarray)):
if resolve_scalar_dtype(divisor) in ["float64", "int64", "uint64", "bool"]:
acmd = "fmod2vs_" + resolve_scalar_dtype(divisor)
else: # this condition *should* be impossible because of the isSupportedNumber check
raise TypeError(f"Scalar divisor type {resolve_scalar_dtype(divisor)} not allowed in fmod")
cmdstring = f"{acmd}<{dividend.dtype},{dividend.ndim}>"

elif not (isinstance(dividend, pdarray) and isinstance(divisor, pdarray)) :
if resolve_scalar_dtype(dividend) in ['float64', 'int64', 'uint64', 'bool'] :
acmd = 'fmod2sv_'+resolve_scalar_dtype(dividend)
else : # this condition *should* be impossible because of the isSupportedNumber check
elif not (isinstance(dividend, pdarray) and isinstance(divisor, pdarray)):
if resolve_scalar_dtype(dividend) in ["float64", "int64", "uint64", "bool"]:
acmd = "fmod2sv_" + resolve_scalar_dtype(dividend)
else: # this condition *should* be impossible because of the isSupportedNumber check
raise TypeError(f"Scalar dividend type {resolve_scalar_dtype(dividend)} not allowed in fmod")
cmdstring = f"{acmd}<{divisor.dtype},{divisor.ndim}>" # type: ignore[union-attr]

else:
m = mod(dividend, divisor)
return _create_scalar_array(m)

# We reach here if this was any case other than scalar & scalar
# We reach here if this was any case other than scalar & scalar

return create_pdarray(
cast(
Expand Down
6 changes: 5 additions & 1 deletion arkouda/pdarraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ def array(
# early out if we would have more uint arrays than can fit in max_bits
early_out = (max_bits // 64) + (max_bits % 64 != 0) if max_bits != -1 else float("inf")
while any(a != 0) and len(uint_arrays) < early_out:
low, a = a % 2**64, a // 2**64
if isinstance(a, np.ndarray):
# numpy arrays do not support sizes > 2**64 so this is a short process.
low, a = a, np.zeros_like(a)
else:
low, a = a % 2**64, a // 2**64
uint_arrays.append(array(np.array(low, dtype=np.uint), dtype=akuint64))
return bigint_from_uint_arrays(uint_arrays[::-1], max_bits=max_bits)
except TypeError:
Expand Down
2 changes: 1 addition & 1 deletion arkouda/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def convert_bytes(nbytes, unit="B"):


def is_numeric(
arry: Union[pdarray, Strings, Categorical, "Series", "Index"] # noqa: F821
arry: Union[pdarray, Strings, Categorical, "Series", "Index"], # noqa: F821
) -> builtins.bool:
"""
Check if the dtype of the given array is numeric.
Expand Down
Loading
Loading