BUG: sparse.dok_matrix.fromkeys method totally nonfunctional
See original GitHub issueDescribe your issue.
The fromkeys
method of sparse.dok_matrix
returns an error. If it is called in the form scipy.sparse.dok_matrix.fromkeys(keys, values=1)
it throws TypeError: dok_matrix.fromkeys() takes no keyword arguments
. If called as scipy.sparse.dok_matrix.fromkeys(keys)
or scipy.sparse.dok_matrix.fromkeys(keys, 1)
it throws TypeError: __init__() missing 1 required positional argument: 'arg1'
. The content of keys
and values
do not seem to matter.
The first error contradicts the documentation for the method, which seems to have been inherited from the docs for Python dicts. The two disagree on whether values
is a positional or keyword argument.
Reproducing Code Example
import scipy
edges = [(0,1),(1,2),(2,0)]
scipy.sparse.dok_matrix.fromkeys(edges, values=1)
scipy.sparse.dok_matrix.fromkeys(edges, 1)
scipy.sparse.dok_matrix.fromkeys(edges)
Error message
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: dok_matrix.fromkeys() takes no keyword arguments
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'arg1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'arg1'
SciPy/NumPy/Python version information
1.7.2 1.21.4 sys.version_info(major=3, minor=9, micro=8, releaselevel=‘final’, serial=0)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
scipy.sparse.dok_matrix — SciPy v1.9.3 Manual
This is an efficient structure for constructing sparse matrices incrementally. This can be instantiated in several ways: dok_matrix(D). with a dense matrix, ...
Read more >Scipy Ref | PDF | Integral | Mathematical Optimization - Scribd
3.15 Sparse linear algebra (scipy.sparse.linalg) . ... The functions and classes available in SciPy use this method for on-line documentation.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One way to address this issue might be to override the
fromkeys
classmethod and have it return a NotImplementedError that points users toward the above workaround.Here’s an implementation that should work: