Skip to content

Commit

Permalink
Testing: Fix failing tests due to Numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jul 9, 2024
1 parent 947c48b commit 81a3f0d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spyder/widgets/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ def __init__(self):
'ddataframe': test_df,
'None': None,
'unsupported1': np.arccos,
'unsupported2': np.cast,
'unsupported2': np.asarray,
# Test for spyder-ide/spyder#3518.
'big_struct_array': np.zeros(1000, dtype=[('ID', 'f8'),
('param1', 'f8', 5000)]),
Expand Down
76 changes: 57 additions & 19 deletions spyder/widgets/tests/test_collectioneditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Third party imports
import numpy
from packaging.version import parse
import pandas
import pytest
from flaky import flaky
Expand Down Expand Up @@ -333,29 +334,66 @@ def test_shows_dataframeeditor_when_editing_index(monkeypatch):


def test_sort_numpy_numeric_collectionsmodel():
if parse(numpy.__version__) >= parse("2.0.0"):
np20 = True
else:
np20 = False

var_list = [
numpy.float64(1e16), numpy.float64(10), numpy.float64(1),
numpy.float64(0.1), numpy.float64(1e-6),
numpy.float64(0), numpy.float64(-1e-6), numpy.float64(-1),
numpy.float64(-10), numpy.float64(-1e16)
]
numpy.float64(1e16),
numpy.float64(10),
numpy.float64(1),
numpy.float64(0.1),
numpy.float64(1e-6),
numpy.float64(0),
numpy.float64(-1e-6),
numpy.float64(-1),
numpy.float64(-10),
numpy.float64(-1e16),
]
cm = CollectionsModel(MockParent(), var_list)
assert cm.rowCount() == 10
assert cm.columnCount() == 4
cm.sort(0) # sort by index
assert data_table(cm, 10, 4) == [list(range(0, 10)),
[u'float64']*10,
[1]*10,
['1e+16', '10.0', '1.0', '0.1',
'1e-06', '0.0', '-1e-06',
'-1.0', '-10.0', '-1e+16']]
cm.sort(3) # sort by value
assert data_table(cm, 10, 4) == [list(range(9, -1, -1)),
[u'float64']*10,
[1]*10,
['-1e+16', '-10.0', '-1.0',
'-1e-06', '0.0', '1e-06',
'0.1', '1.0', '10.0', '1e+16']]

# Sort by index
cm.sort(0)
assert data_table(cm, 10, 4) == [
list(range(0, 10)),
["float64"] * 10,
[1] * 10,
[
"np.float64(1e+16)" if np20 else "1e+16",
"np.float64(10.0)" if np20 else "10.0",
"np.float64(1.0)" if np20 else "1.0",
"np.float64(0.1)" if np20 else "0.1",
"np.float64(1e-06)" if np20 else "1e-06",
"np.float64(0.0)" if np20 else "0.0",
"np.float64(-1e-06)" if np20 else "-1e-06",
"np.float64(-1.0)" if np20 else "-1.0",
"np.float64(-10.0)" if np20 else "-10.0",
"np.float64(-1e+16)" if np20 else "-1e+16",
],
]

# Sort by value
cm.sort(3)
assert data_table(cm, 10, 4) == [
list(range(9, -1, -1)),
["float64"] * 10,
[1] * 10,
[
"np.float64(-1e+16)" if np20 else "-1e+16",
"np.float64(-10.0)" if np20 else "-10.0",
"np.float64(-1.0)" if np20 else "-1.0",
"np.float64(-1e-06)" if np20 else "-1e-06",
"np.float64(0.0)" if np20 else "0.0",
"np.float64(1e-06)" if np20 else "1e-06",
"np.float64(0.1)" if np20 else "0.1",
"np.float64(1.0)" if np20 else "1.0",
"np.float64(10.0)" if np20 else "10.0",
"np.float64(1e+16)" if np20 else "1e+16",
],
]


def test_sort_float_collectionsmodel():
Expand Down

0 comments on commit 81a3f0d

Please sign in to comment.