Skip to content

Commit

Permalink
fix: revert Numpy version 2.0.0 incompatibility with Prophet (#55)
Browse files Browse the repository at this point in the history
* fix: revert Numpy version 2.0.0 incompatibility with Prophet
  • Loading branch information
jcabrero authored Jul 30, 2024
1 parent fbacdd2 commit bb1015f
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 204 deletions.
24 changes: 23 additions & 1 deletion nada_numpy/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# pylint:disable=too-many-lines

from typing import Any, Callable, Optional, Sequence, Union, get_args
from typing import Any, Callable, Optional, Sequence, Union, get_args, overload

import numpy as np
from nada_dsl import (Boolean, Input, Integer, Output, Party, PublicInteger,
Expand Down Expand Up @@ -870,6 +870,28 @@ def item(self, *args, **kwargs):
return NadaArray(result)
return result

@overload
def itemset(self, value: Any): ...
@overload
def itemset(self, item: Any, value: Any): ...

# pylint:disable=missing-function-docstring
@copy_metadata(np.ndarray.itemset)
def itemset(self, *args, **kwargs):
value = None
if len(args) == 1:
value = args[0]
elif len(args) == 2:
value = args[1]
else:
value = kwargs["value"]

_check_type_compatibility(value, self.dtype)
result = self.inner.itemset(*args, **kwargs)
if isinstance(result, np.ndarray):
return NadaArray(result)
return result

# pylint:disable=missing-function-docstring
@copy_metadata(np.ndarray.prod)
def prod(self, *args, **kwargs):
Expand Down
393 changes: 194 additions & 199 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "nada-numpy"
version = "0.3.1"
version = "0.3.2"
description = "Nada-Numpy is a Python library designed for algebraic operations on NumPy-like array objects on top of Nada DSL and Nillion Network."
authors = ["José Cabrero-Holgueras <jose.cabrero@nillion.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
numpy = "^2.0.0"
numpy = "^1.26.4"
nada-dsl = "^0.4.0"
py-nillion-client = "^0.4.0"
nillion-python-helpers = "^0.2.3"
Expand Down
1 change: 1 addition & 0 deletions tests/nada-tests/src/supported_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def nada_main():

f = na.array([1], parties[0], "F", SecretInteger)
f.fill(Integer(40))
f.itemset(0, f.item(0) + Integer(2))
with pytest.raises(Exception):
f.itemset(0, na.rational(1))
f = f.tolist()[0]
Expand Down
2 changes: 2 additions & 0 deletions tests/nada-tests/src/supported_operations_return_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def nada_main():
check_array(f)
f.fill(Integer(40))
check_array(f)
f.itemset(0, f.item(0) + Integer(2))
check_array(f)
assert isinstance(f.tolist(), list)
f = f.tolist()[0] # Not an array

Expand Down
2 changes: 1 addition & 1 deletion tests/nada-tests/tests/supported_operations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ expected_outputs:
out_4:
SecretInteger: 21
out_5:
Integer: 40
Integer: 42
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ expected_outputs:
out_4:
SecretInteger: 21
out_5:
Integer: 40
Integer: 42

0 comments on commit bb1015f

Please sign in to comment.