@@ -19,7 +19,7 @@ class TestSparseVector:
1919 def test_list (self ):
2020 vec = SparseVector ([1 , 0 , 2 , 0 , 3 , 0 ])
2121 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
22- if np is not None :
22+ if NUMPY_AVAILABLE :
2323 assert np .array_equal (vec .to_numpy (), [1 , 0 , 2 , 0 , 3 , 0 ])
2424 assert vec .indices () == [0 , 2 , 4 ]
2525
@@ -28,7 +28,7 @@ def test_list_dimensions(self):
2828 SparseVector ([1 , 0 , 2 , 0 , 3 , 0 ], 6 ) # ty: ignore[invalid-argument-type]
2929 assert str (error .value ) == 'extra argument'
3030
31- @pytest .mark .skipif (NUMPY_AVAILABLE , reason = 'NumPy required' )
31+ @pytest .mark .skipif (not NUMPY_AVAILABLE , reason = 'NumPy required' )
3232 def test_ndarray (self ):
3333 vec = SparseVector (np .array ([1 , 0 , 2 , 0 , 3 , 0 ]))
3434 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
@@ -44,41 +44,41 @@ def test_dict_no_dimensions(self):
4444 SparseVector ({0 : 1 , 2 : 2 , 4 : 3 })
4545 assert str (error .value ) == 'missing dimensions'
4646
47- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
47+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
4848 def test_coo_array (self ):
4949 arr = coo_array (np .array ([1 , 0 , 2 , 0 , 3 , 0 ]))
5050 vec = SparseVector (arr )
5151 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
5252 assert vec .indices () == [0 , 2 , 4 ]
5353
54- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
54+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
5555 def test_coo_array_dimensions (self ):
5656 with pytest .raises (ValueError ) as error :
5757 SparseVector (coo_array (np .array ([1 , 0 , 2 , 0 , 3 , 0 ])), 6 ) # ty: ignore[invalid-argument-type]
5858 assert str (error .value ) == 'extra argument'
5959
60- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
60+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
6161 def test_coo_matrix (self ):
6262 mat = coo_matrix (np .array ([1 , 0 , 2 , 0 , 3 , 0 ]))
6363 vec = SparseVector (mat )
6464 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
6565 assert vec .indices () == [0 , 2 , 4 ]
6666
67- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
67+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
6868 def test_dok_array (self ):
6969 arr = coo_array (np .array ([1 , 0 , 2 , 0 , 3 , 0 ])).todok ()
7070 vec = SparseVector (arr )
7171 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
7272 assert vec .indices () == [0 , 2 , 4 ]
7373
74- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
74+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
7575 def test_csr_array (self ):
7676 arr = csr_array (np .array ([[1 , 0 , 2 , 0 , 3 , 0 ]]))
7777 vec = SparseVector (arr )
7878 assert vec .to_list () == [1 , 0 , 2 , 0 , 3 , 0 ]
7979 assert vec .indices () == [0 , 2 , 4 ]
8080
81- @pytest .mark .skipif (SCIPY_AVAILABLE , reason = 'SciPy required' )
81+ @pytest .mark .skipif (not SCIPY_AVAILABLE , reason = 'SciPy required' )
8282 def test_csr_matrix (self ):
8383 mat = csr_matrix (np .array ([1 , 0 , 2 , 0 , 3 , 0 ]))
8484 vec = SparseVector (mat )
@@ -104,7 +104,7 @@ def test_indices(self):
104104 def test_values (self ):
105105 assert SparseVector ([1 , 0 , 2 , 0 , 3 , 0 ]).values () == [1 , 2 , 3 ]
106106
107- @pytest .mark .skipif (NUMPY_AVAILABLE or SCIPY_AVAILABLE , reason = 'NumPy and SciPy required' )
107+ @pytest .mark .skipif (not NUMPY_AVAILABLE or not SCIPY_AVAILABLE , reason = 'NumPy and SciPy required' )
108108 def test_to_coo (self ):
109109 assert np .array_equal (SparseVector ([1 , 0 , 2 , 0 , 3 , 0 ]).to_coo ().toarray (), [[1 , 0 , 2 , 0 , 3 , 0 ]])
110110
@@ -118,7 +118,7 @@ def test_from_text(self):
118118 assert vec .indices () == [0 , 2 , 4 ]
119119 assert vec .values () == [1.5 , 2 , 3 ]
120120 assert vec .to_list () == [1.5 , 0 , 2 , 0 , 3 , 0 ]
121- if np is not None :
121+ if NUMPY_AVAILABLE :
122122 assert np .array_equal (vec .to_numpy (), [1.5 , 0 , 2 , 0 , 3 , 0 ])
123123
124124 def test_from_binary (self ):
@@ -128,6 +128,6 @@ def test_from_binary(self):
128128 assert vec .indices () == [0 , 2 , 4 ]
129129 assert vec .values () == [1.5 , 2 , 3 ]
130130 assert vec .to_list () == [1.5 , 0 , 2 , 0 , 3 , 0 ]
131- if np is not None :
131+ if NUMPY_AVAILABLE :
132132 assert np .array_equal (vec .to_numpy (), [1.5 , 0 , 2 , 0 , 3 , 0 ])
133133 assert vec .to_binary () == data
0 commit comments