question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pandas.Index.to_numpy() method's arguments not properly typed

See original GitHub issue

Describe 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-stubs1.4.3.220829

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dr-Irvcommented, Sep 7, 2022

closed via #270

1reaction
Dr-Irvcommented, Sep 5, 2022

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 the to_numpy() tests to use that pattern.

Correct me if I’m wrong please, I should add similar functions:

  • for indexes, create an index, call to_numpy and assert the type
  • for series, create a serie, call to_numpy and assert the type

Yes, you should add similar functions for all the to_numpy() variants.

Also. It seems like there is an addition here. Should I include the addition in the current PR or create a different one ?

You can do one PR, that includes fixes to all the to_numpy() stubs, and the appropriate tests.

Thanks in advance for your contribution!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found