pandas.Index.to_numpy() method's arguments not properly typed
See original GitHub issueDescribe the bug The pandas.Index.to_numpy() method takes arguments, but mypy complains about them, whether they are positional or keyword.
To Reproduce
import pandas as pd df = pd.DataFrame({“A”: [1, 2, 3], “B”: [4, 5, 6]}) array = df.index.to_numpy(dtype=“int32”)
This yields error: Unexpected keyword argument “dtype” for “to_numpy” of “Index”
import pandas as pd df = pd.DataFrame({“A”: [1, 2, 3], “B”: [4, 5, 6]}) array = df.index.to_numpy(dtype=“int32”)
This yields error: Too many arguments for “to_numpy” of "Index
Please complete the following information:
- OS: Windows
- OS Version 10
- python version 3.10
- version of type checker: latest
- version of installed
pandas-stubs
1.4.3.220829
Issue Analytics
- State:
- Created a year ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How do I convert a Pandas series or index to a NumPy array?
It returns a list of indices. It is a method defined on pandas index. While calling values first is a possibility, delegating the...
Read more >Indexing and selecting data — pandas 1.5.2 documentation
A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above).
Read more >Indexing on ndarrays — NumPy v1.25.dev0 Manual
ndarrays can be indexed using the standard Python x[obj] syntax, where x is the array and obj the selection. There are different kinds...
Read more >Plotly express arguments in Python
bar or px.scatter expect to operate on column-oriented data of the type you might store in a Pandas DataFrame (in either "long" or...
Read more >Convert Pandas Series to NumPy Array - Spark by {Examples}
Each element in ndarray is an object of the data-type object (called dtype ). Using pandas Series.to_numpy() function we can convert Series to ......
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 FreeTop 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
Top GitHub Comments
closed via #270
With respect to the tests not having
check(assert_type(...))
, that’s a legacy issue. The original stubs didn’t have them, but when we are adding new tests, we are requiring it. Eventually, all the tests should use that paradigm. Would be good if you fix all theto_numpy()
tests to use that pattern.Yes, you should add similar functions for all the
to_numpy()
variants.You can do one PR, that includes fixes to all the
to_numpy()
stubs, and the appropriate tests.Thanks in advance for your contribution!