Created
January 3, 2023 21:49
-
-
Save mweinelt/c4cf38def687bf68862a6632fff7cc87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pynndescent> ============================= test session starts ============================== | |
pynndescent> platform linux -- Python 3.10.9, pytest-7.2.0, pluggy-1.0.0 | |
pynndescent> rootdir: /build/pynndescent-0.5.8 | |
pynndescent> collected 143 items / 4 deselected / 139 selected | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py ..................FFFFFFFFF......... [ 25%] | |
pynndescent> ......... [ 32%] | |
pynndescent> pynndescent/tests/test_pynndescent_.py ................................. [ 56%] | |
pynndescent> ........................ [ 73%] | |
pynndescent> pynndescent/tests/test_rank.py ..................................... [100%] | |
pynndescent> | |
pynndescent> =================================== FAILURES =================================== | |
pynndescent> _____________________ test_sparse_spatial_check[euclidean] _____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 61 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'euclidean', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2039: in pairwise_distances | |
pynndescent> return _parallel_pairwise(X, Y, func, n_jobs, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:1579: in _parallel_pairwise | |
pynndescent> return func(X, Y, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:300: in euclidean_distances | |
pynndescent> X, Y = check_pairwise_arrays(X, Y) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0. , -0.02546946, 0. , 0. , 0.45841283, | |
pynndescent> 0. , 0. , 0. ... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> _____________________ test_sparse_spatial_check[manhattan] _____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 72 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'manhattan', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2039: in pairwise_distances | |
pynndescent> return _parallel_pairwise(X, Y, func, n_jobs, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:1579: in _parallel_pairwise | |
pynndescent> return func(X, Y, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:948: in manhattan_distances | |
pynndescent> X, Y = check_pairwise_arrays(X, Y) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[-1.6336606 , -0.32145873, 0. , 0. , 0. , | |
pynndescent> 1.3702277 , 0. , -0.711960... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> _____________________ test_sparse_spatial_check[chebyshev] _____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 63 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'chebyshev', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0. , 0. , 0. , 0.11813139, 0. , | |
pynndescent> 0. , -0.21905616, 0.417503... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> _____________________ test_sparse_spatial_check[minkowski] _____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 82 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'minkowski', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0.0000000e+00, 0.0000000e+00, -1.0411386e+00, 0.0000000e+00, | |
pynndescent> -5.6272256e-01, 0.0000000e+00, 0.0...0e+00, 0.0000000e+00, | |
pynndescent> 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> ______________________ test_sparse_spatial_check[hamming] ______________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 62 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'hamming', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0. , 0. , 0. , 0. , 0. , | |
pynndescent> 0. , 0. , 0. ... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> _____________________ test_sparse_spatial_check[canberra] ______________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 81 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'canberra', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0. , 0. , 0. , -0.14346407, 0. , | |
pynndescent> 0.75328195, 0.39030677, -2.304208... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> ______________________ test_sparse_spatial_check[cosine] _______________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 69 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'cosine', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2039: in pairwise_distances | |
pynndescent> return _parallel_pairwise(X, Y, func, n_jobs, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:1579: in _parallel_pairwise | |
pynndescent> return func(X, Y, **kwds) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:1000: in cosine_distances | |
pynndescent> S = cosine_similarity(X, Y) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:1393: in cosine_similarity | |
pynndescent> X, Y = check_pairwise_arrays(X, Y) | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0.7063732 , 0. , 0. , 0. , 0. , | |
pynndescent> 0. , 0. , 0. ... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> ____________________ test_sparse_spatial_check[braycurtis] _____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 64 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'braycurtis', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0. , 0. , 0.08100726, 0. , -0.64761156, | |
pynndescent> 0. , 0. , 0. ... , 0. , | |
pynndescent> 0. , 0. , 0. , 0. , 0. ]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> ____________________ test_sparse_spatial_check[correlation] ____________________ | |
pynndescent> | |
pynndescent> sparse_spatial_data = <12x20 sparse matrix of type '<class 'numpy.float32'>' | |
pynndescent> with 68 stored elements in Compressed Sparse Row format> | |
pynndescent> metric = 'correlation', decimal = 6 | |
pynndescent> | |
pynndescent> @pytest.mark.parametrize( | |
pynndescent> "metric", | |
pynndescent> [ | |
pynndescent> "euclidean", | |
pynndescent> "manhattan", | |
pynndescent> "chebyshev", | |
pynndescent> "minkowski", | |
pynndescent> "hamming", | |
pynndescent> "canberra", | |
pynndescent> "cosine", | |
pynndescent> "braycurtis", | |
pynndescent> "correlation", | |
pynndescent> ], | |
pynndescent> ) | |
pynndescent> def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6): | |
pynndescent> if metric in spdist.sparse_named_distances: | |
pynndescent> > dist_matrix = pairwise_distances( | |
pynndescent> sparse_spatial_data.todense().astype(np.float32), metric=metric | |
pynndescent> ) | |
pynndescent> | |
pynndescent> pynndescent/tests/test_distances.py:111: | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:2027: in pairwise_distances | |
pynndescent> X, Y = check_pairwise_arrays( | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/metrics/pairwise.py:146: in check_pairwise_arrays | |
pynndescent> X = Y = check_array( | |
pynndescent> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pynndescent> | |
pynndescent> array = matrix([[ 0.0000000e+00, 0.0000000e+00, 4.1397369e-01, -5.2132380e-01, | |
pynndescent> 1.3164551e+00, 0.0000000e+00, 0.0...0e+00, 0.0000000e+00, | |
pynndescent> 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]], | |
pynndescent> dtype=float32) | |
pynndescent> accept_sparse = 'csr' | |
pynndescent> | |
pynndescent> def check_array( | |
pynndescent> array, | |
pynndescent> accept_sparse=False, | |
pynndescent> *, | |
pynndescent> accept_large_sparse=True, | |
pynndescent> dtype="numeric", | |
pynndescent> order=None, | |
pynndescent> copy=False, | |
pynndescent> force_all_finite=True, | |
pynndescent> ensure_2d=True, | |
pynndescent> allow_nd=False, | |
pynndescent> ensure_min_samples=1, | |
pynndescent> ensure_min_features=1, | |
pynndescent> estimator=None, | |
pynndescent> input_name="", | |
pynndescent> ): | |
pynndescent> | |
pynndescent> """Input validation on an array, list, sparse matrix or similar. | |
pynndescent> | |
pynndescent> By default, the input is checked to be a non-empty 2D array containing | |
pynndescent> only finite values. If the dtype of the array is object, attempt | |
pynndescent> converting to float, raising on failure. | |
pynndescent> | |
pynndescent> Parameters | |
pynndescent> ---------- | |
pynndescent> array : object | |
pynndescent> Input object to check / convert. | |
pynndescent> | |
pynndescent> accept_sparse : str, bool or list/tuple of str, default=False | |
pynndescent> String[s] representing allowed sparse matrix formats, such as 'csc', | |
pynndescent> 'csr', etc. If the input is sparse but not in the allowed format, | |
pynndescent> it will be converted to the first listed format. True allows the input | |
pynndescent> to be any format. False means that a sparse matrix input will | |
pynndescent> raise an error. | |
pynndescent> | |
pynndescent> accept_large_sparse : bool, default=True | |
pynndescent> If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by | |
pynndescent> accept_sparse, accept_large_sparse=False will cause it to be accepted | |
pynndescent> only if its indices are stored with a 32-bit dtype. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> | |
pynndescent> dtype : 'numeric', type, list of type or None, default='numeric' | |
pynndescent> Data type of result. If None, the dtype of the input is preserved. | |
pynndescent> If "numeric", dtype is preserved unless array.dtype is object. | |
pynndescent> If dtype is a list of types, conversion on the first type is only | |
pynndescent> performed if the dtype of the input is not in the list. | |
pynndescent> | |
pynndescent> order : {'F', 'C'} or None, default=None | |
pynndescent> Whether an array will be forced to be fortran or c-style. | |
pynndescent> When order is None (default), then if copy=False, nothing is ensured | |
pynndescent> about the memory layout of the output array; otherwise (copy=True) | |
pynndescent> the memory layout of the returned array is kept as close as possible | |
pynndescent> to the original array. | |
pynndescent> | |
pynndescent> copy : bool, default=False | |
pynndescent> Whether a forced copy will be triggered. If copy=False, a copy might | |
pynndescent> be triggered by a conversion. | |
pynndescent> | |
pynndescent> force_all_finite : bool or 'allow-nan', default=True | |
pynndescent> Whether to raise an error on np.inf, np.nan, pd.NA in array. The | |
pynndescent> possibilities are: | |
pynndescent> | |
pynndescent> - True: Force all values of array to be finite. | |
pynndescent> - False: accepts np.inf, np.nan, pd.NA in array. | |
pynndescent> - 'allow-nan': accepts only np.nan and pd.NA values in array. Values | |
pynndescent> cannot be infinite. | |
pynndescent> | |
pynndescent> .. versionadded:: 0.20 | |
pynndescent> ``force_all_finite`` accepts the string ``'allow-nan'``. | |
pynndescent> | |
pynndescent> .. versionchanged:: 0.23 | |
pynndescent> Accepts `pd.NA` and converts it into `np.nan` | |
pynndescent> | |
pynndescent> ensure_2d : bool, default=True | |
pynndescent> Whether to raise a value error if array is not 2D. | |
pynndescent> | |
pynndescent> allow_nd : bool, default=False | |
pynndescent> Whether to allow array.ndim > 2. | |
pynndescent> | |
pynndescent> ensure_min_samples : int, default=1 | |
pynndescent> Make sure that the array has a minimum number of samples in its first | |
pynndescent> axis (rows for a 2D array). Setting to 0 disables this check. | |
pynndescent> | |
pynndescent> ensure_min_features : int, default=1 | |
pynndescent> Make sure that the 2D array has some minimum number of features | |
pynndescent> (columns). The default value of 1 rejects empty datasets. | |
pynndescent> This check is only enforced when the input data has effectively 2 | |
pynndescent> dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0 | |
pynndescent> disables this check. | |
pynndescent> | |
pynndescent> estimator : str or estimator instance, default=None | |
pynndescent> If passed, include the name of the estimator in warning messages. | |
pynndescent> | |
pynndescent> input_name : str, default="" | |
pynndescent> The data name used to construct the error message. In particular | |
pynndescent> if `input_name` is "X" and the data has NaN values and | |
pynndescent> allow_nan is False, the error message will link to the imputer | |
pynndescent> documentation. | |
pynndescent> | |
pynndescent> .. versionadded:: 1.1.0 | |
pynndescent> | |
pynndescent> Returns | |
pynndescent> ------- | |
pynndescent> array_converted : object | |
pynndescent> The converted and validated array. | |
pynndescent> """ | |
pynndescent> if isinstance(array, np.matrix): | |
pynndescent> > raise TypeError( | |
pynndescent> "np.matrix is not supported. Please convert to a numpy array with " | |
pynndescent> "np.asarray. For more information see: " | |
pynndescent> "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html" | |
pynndescent> ) | |
pynndescent> E TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html | |
pynndescent> | |
pynndescent> /nix/store/cn7gxxzfngznz7kkwcmcaa379sg8w8vb-python3.10-scikit-learn-1.2.0/lib/python3.10/site-packages/sklearn/utils/validation.py:737: TypeError | |
pynndescent> =========================== short test summary info ============================ | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[euclidean] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[manhattan] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[chebyshev] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[minkowski] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[hamming] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[canberra] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[cosine] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[braycurtis] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> FAILED pynndescent/tests/test_distances.py::test_sparse_spatial_check[correlation] - TypeError: np.matrix is not supported. Please convert to a numpy array with... | |
pynndescent> =========== 9 failed, 130 passed, 4 deselected in 192.54s (0:03:12) ============ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment