Skip to content

Commit 416fd82

Browse files
authored
Merge pull request #6850 from ales-erjavec/numpy2.0
[ENH] Numpy 2.0 compatibility
2 parents 357b3af + 88f99c7 commit 416fd82

25 files changed

+37
-38
lines changed

Orange/classification/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pull members from modules to Orange.classification namespace
2-
# pylint: disable=wildcard-import
2+
# pylint: disable=wildcard-import,broad-except
33

44
from .base_classification import (ModelClassification as Model,
55
LearnerClassification as Learner,
@@ -23,7 +23,7 @@
2323
from .scoringsheet import *
2424
try:
2525
from .catgb import *
26-
except ModuleNotFoundError:
26+
except Exception:
2727
pass
2828
from .gb import *
2929
try:

Orange/data/io_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def get_arrays(self) -> Tuple[np.ndarray, np.ndarray,
381381
(self.cols_W, float))
382382
X, Y, M, W = [self._list_into_ndarray(lst, dt) for lst, dt in lists]
383383
if X is None:
384-
X = np.empty((self.data.shape[0], 0), dtype=np.float_)
384+
X = np.empty((self.data.shape[0], 0), dtype=np.float64)
385385
return X, Y, M, W
386386

387387
@staticmethod
@@ -393,7 +393,7 @@ def _list_into_ndarray(lst: List, dtype=None) -> Optional[np.ndarray]:
393393
if dtype is not None:
394394
array.astype(dtype)
395395
else:
396-
assert array.dtype == np.float_
396+
assert array.dtype == np.float64
397397
return array
398398

399399

Orange/data/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def scale(values, min=0, max=1):
5050
"""Return values scaled to [min, max]"""
5151
if len(values) == 0:
5252
return np.array([])
53-
minval = np.float_(bn.nanmin(values))
53+
minval = np.float64(bn.nanmin(values))
5454
ptp = bn.nanmax(values) - minval
5555
if ptp == 0:
5656
return np.clip(values, min, max)

Orange/preprocess/_relieff.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ cdef tuple prepare(X, y, is_discrete, contingencies):
371371
is_defined = np.logical_not(np.isnan(y))
372372
X = X[is_defined]
373373
y = y[is_defined]
374-
attr_stats = np.row_stack((np.nanmean(X, 0), np.nanstd(X, 0)))
374+
attr_stats = np.vstack((np.nanmean(X, 0), np.nanstd(X, 0)))
375375
is_discrete = np.asarray(is_discrete, dtype=np.int8)
376376
contingency_tables(X, y, is_discrete, contingencies)
377377
return X, y, attr_stats, is_discrete

Orange/preprocess/discretize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def transform(self, c):
4444
if sp.issparse(c):
4545
return self.digitize(c, self.points)
4646
elif c.size:
47-
return np.where(np.isnan(c), np.NaN, self.digitize(c, self.points))
47+
return np.where(np.isnan(c), np.nan, self.digitize(c, self.points))
4848
else:
4949
return np.array([], dtype=int)
5050

Orange/preprocess/remove.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def remove_unused_values(var, data):
233233
if len(unique) == len(var.values):
234234
return var
235235
used_values = [var.values[i] for i in unique]
236-
translation_table = np.array([np.NaN] * len(var.values))
236+
translation_table = np.array([np.nan] * len(var.values))
237237
translation_table[unique] = range(len(used_values))
238238
return DiscreteVariable(var.name, values=used_values, sparse=var.sparse,
239239
compute_value=Lookup(var, translation_table))

Orange/regression/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ..classification.simple_tree import *
1818
try:
1919
from .catgb import *
20-
except ModuleNotFoundError:
20+
except Exception:
2121
pass
2222
from .gb import *
2323
try:

Orange/tests/test_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def test_multinomial(self):
347347
def test_nan_columns(self):
348348
data = Orange.data.Table("iris")
349349
with data.unlocked():
350-
data.X[:, (1, 3)] = np.NaN
350+
data.X[:, (1, 3)] = np.nan
351351
lr = LogisticRegressionLearner()
352352
cv = CrossValidation(k=2, store_models=True)
353353
res = cv(data, [lr])

Orange/tests/test_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def test_preprocessor_chaining(self):
430430
domain = Domain([DiscreteVariable("a", values="01"),
431431
DiscreteVariable("b", values="01")],
432432
DiscreteVariable("y", values="01"))
433-
table = Table.from_list(domain, [[0, 1], [1, np.NaN]], [0, 1])
433+
table = Table.from_list(domain, [[0, 1], [1, np.nan]], [0, 1])
434434
pre1 = Continuize()(Impute()(table))
435435
pre2 = table.transform(pre1.domain)
436436
np.testing.assert_almost_equal(pre1.X, pre2.X)

Orange/tests/test_preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ class TestRemoveNaNColumns(unittest.TestCase):
8080
def test_column_filtering(self):
8181
data = Table("iris")
8282
with data.unlocked():
83-
data.X[:, (1, 3)] = np.NaN
83+
data.X[:, (1, 3)] = np.nan
8484

8585
new_data = RemoveNaNColumns()(data)
8686
self.assertEqual(len(new_data.domain.attributes),
8787
len(data.domain.attributes) - 2)
8888

8989
data = Table("iris")
9090
with data.unlocked():
91-
data.X[0, 0] = np.NaN
91+
data.X[0, 0] = np.nan
9292
new_data = RemoveNaNColumns()(data)
9393
self.assertEqual(len(new_data.domain.attributes),
9494
len(data.domain.attributes))

0 commit comments

Comments
 (0)