Skip to content

Commit

Permalink
Closes #4098: upgrade to numpy 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Feb 27, 2025
1 parent 1a89d73 commit 36eef1c
Show file tree
Hide file tree
Showing 23 changed files with 3,432 additions and 341 deletions.
4 changes: 2 additions & 2 deletions arkouda-env-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
- defaults
dependencies:
- python>=3.9 # minimum 3.9
- numpy>=1.24.1,<2.0
- numpy>=2.0
- pandas>=1.4.0,!=2.2.0
- pyzmq>=20.0.0
- tabulate
Expand All @@ -20,7 +20,7 @@ dependencies:
- libiconv
- libidn2
- jupyter
- scipy
- scipy<=1.13.1
- pytest>=6.0
- pytest-env
- cloudpickle
Expand Down
4 changes: 2 additions & 2 deletions arkouda-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
- defaults
dependencies:
- python>=3.9 # minimum 3.9
- numpy>=1.24.1,<2.0
- numpy>=2.0
- pandas>=1.4.0,!=2.2.0
- pyzmq>=20.0.0
- tabulate
Expand All @@ -20,7 +20,7 @@ dependencies:
- libiconv
- libidn2
- jupyter
- scipy
- scipy<=1.13.1
- pytest>=6.0
- pytest-env
- cloudpickle
Expand Down
33 changes: 2 additions & 31 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,34 +17,29 @@
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,
timedelta64,
typename,
ubyte,
uint,
uintc,
Expand All @@ -66,20 +50,7 @@
void,
)

from arkouda.numpy import (
_builtins,
_mat,
_typing,
char,
ctypeslib,
dtypes,
exceptions,
fft,
lib,
linalg,
ma,
rec,
)
from arkouda.numpy.lib import *
from arkouda.numpy._builtins import *
from arkouda.numpy._mat import *
from arkouda.numpy._typing import *
Expand Down
38 changes: 37 additions & 1 deletion arkouda/numpy/_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@

from arkouda.client import generic_msg
from arkouda.groupbyclass import GroupBy, groupable
from arkouda.numpy.dtypes import _datatype_check, bigint
from arkouda.numpy.dtypes import (
_datatype_check,
_is_dtype_in_union,
bigint,
)
from arkouda.numpy.dtypes import bool_ as ak_bool
from arkouda.numpy.dtypes import dtype as ak_dtype
from arkouda.numpy.dtypes import dtype as akdtype
from arkouda.numpy.dtypes import float64 as ak_float64
from arkouda.numpy.dtypes import int64 as ak_int64
from arkouda.numpy.dtypes import (
int_scalars,
isSupportedInt,
isSupportedNumber,
numeric_scalars,
resolve_scalar_dtype,
Expand Down Expand Up @@ -119,6 +125,36 @@ def _merge_where(new_pda, where, ret):
return new_pda


def can_cast(from_, to) -> ak_bool:
"""
Returns True if cast between data types can occur according to the casting rule.
Parameters
__________
from_: dtype, dtype specifier, NumPy scalar, or pdarray
Data type, NumPy scalar, or array to cast from.
to: dtype or dtype specifier
Data type to cast to.
Return
------
bool
True if cast can occur according to the casting rule.
"""
if isSupportedInt(from_):
if (from_ < 2**64) and (from_ >= 0) and (to == ak_dtype(ak_uint64)):
return True

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)

return False


@typechecked
def cast(
pda: Union[pdarray, Strings, Categorical], # type: ignore
Expand Down
84 changes: 84 additions & 0 deletions arkouda/numpy/dtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,87 @@
)

from .dtypes import *

__all__ = [
"BoolDType",
"ByteDType",
"BytesDType",
"CLongDoubleDType",
"Complex64DType",
"Complex128DType",
"DateTime64DType",
"Float16DType",
"Float32DType",
"Float64DType",
"Int8DType",
"Int16DType",
"Int32DType",
"Int64DType",
"IntDType",
"LongDoubleDType",
"LongDType",
"LongLongDType",
"ObjectDType",
"ShortDType",
"StrDType",
"TimeDelta64DType",
"UByteDType",
"UInt8DType",
"UInt16DType",
"UInt32DType",
"UInt64DType",
"UIntDType",
"ULongDType",
"ULongLongDType",
"UShortDType",
"VoidDType",
"_datatype_check",
"ARKOUDA_SUPPORTED_DTYPES",
"ARKOUDA_SUPPORTED_INTS",
"DType",
"DTypeObjects",
"DTypes",
"NUMBER_FORMAT_STRINGS",
"NumericDTypes",
"ScalarDTypes",
"SeriesDTypes",
"_is_dtype_in_union",
"_val_isinstance_of_union",
"all_scalars",
"bigint",
"bitType",
"bool_",
"bool_scalars",
"complex128",
"complex64",
"dtype",
"float16",
"float32",
"float64",
"float_scalars",
"get_byteorder",
"get_server_byteorder",
"int16",
"int32",
"int64",
"int8",
"intTypes",
"int_scalars",
"isSupportedBool",
"isSupportedDType",
"isSupportedFloat",
"isSupportedInt",
"isSupportedNumber",
"numeric_and_bool_scalars",
"numeric_and_bool_scalars",
"numeric_scalars",
"numpy_scalars",
"resolve_scalar_dtype",
"resolve_scalar_dtype",
"str_",
"str_scalars",
"uint16",
"uint32",
"uint64",
"uint8",
]
31 changes: 26 additions & 5 deletions arkouda/numpy/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,18 @@ def dtype(x):
return bigint()
if isinstance(x, str) and x in ["Strings"]:
return np.dtype(np.str_)
else:
return np.dtype(x)
if isinstance(x, int):
if 0 < x and x < 2**64:
return np.dtype(np.uint64)
elif x >= 2**64:
return bigint()
else:
return np.dtype(np.int64)
if isinstance(x, float):
return np.dtype(np.float64)
if isinstance(x, bool):
return np.dtype(np.bool)
return np.dtype(x)


def _is_dtype_in_union(dtype, union_type) -> builtins.bool:
Expand Down Expand Up @@ -284,7 +294,18 @@ 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()])
Expand Down Expand Up @@ -347,9 +368,9 @@ 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
2 changes: 1 addition & 1 deletion 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.exceptions import RankWarning, TooHardError

__all__ = ["RankWarning", "TooHardError"]
20 changes: 2 additions & 18 deletions arkouda/numpy/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
# flake8: noqa
from numpy import (
RankWarning,
from numpy.lib import (
add_docstring,
add_newdoc,
deprecate,
deprecate_with_doc,
disp,
issubclass_,
issubdtype,
polynomial,
typename,
)

from arkouda.numpy.lib import emath
from arkouda.numpy.lib.emath import *


__all__ = [
"RankWarning",
"add_docstring",
"add_newdoc",
"deprecate",
"deprecate_with_doc",
"disp",
"emath",
"issubclass_",
"issubdtype",
"polynomial",
"typename",
]
3 changes: 3 additions & 0 deletions arkouda/numpy/lib/npyio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from numpy.lib.npyio import DataSource

__all__ = ["DataSource"]
2 changes: 1 addition & 1 deletion arkouda/numpy/rec/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from numpy import format_parser
from numpy.rec import format_parser

__all__ = ["format_parser"]
Loading

0 comments on commit 36eef1c

Please sign in to comment.