Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame.insert should accept np.float32 #1059

Open
tblum opened this issue Nov 28, 2024 · 4 comments
Open

DataFrame.insert should accept np.float32 #1059

tblum opened this issue Nov 28, 2024 · 4 comments
Labels
DataFrame DataFrame data structure

Comments

@tblum
Copy link

tblum commented Nov 28, 2024

Describe the bug
Calling DataFrame.insert with a np.float32 will fail with the following error:

error: Argument 3 to "insert" of "DataFrame" has incompatible type "floating[_32Bit]"; expected "str | bytes | date | datetime | timedelta | <7 more items> | complex | Sequence[Any] | ndarray[Any, Any] | Series[Any] | Index[Any] | None" [arg-type]

@loicdiridollou
Copy link
Contributor

Hey @tblum,
The issue you are facing is linked to the fact that Scalar contains float but this type is not the same as float32.
@Dr-Irv is this something that we should include in the stubs?

@loicdiridollou loicdiridollou added the DataFrame DataFrame data structure label Nov 28, 2024
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 29, 2024

The issue you are facing is linked to the fact that Scalar contains float but this type is not the same as float32.
@Dr-Irv is this something that we should include in the stubs?

Possibly. I'd like to see a more complete example from @tblum before we address this. Would be curious to know if np.float64 also fails, so we may need to add that as well.

@loicdiridollou
Copy link
Contributor

loicdiridollou commented Nov 29, 2024

import numpy as np
import pandas as pd

df = pd.DataFrame({"A": [1, 2, 3]})

df.insert(3, "A", value=np.float32(23.3))
df.insert(3, "A", value=np.float64(23.3))

Both give out the same error:

file.py:6: error: Argument "value" to "insert" of "DataFrame" has incompatible type "floating[_32Bit]";
expected "str | bytes | date | datetime | timedelta | <7 more items> | complex | Sequence[Any] | 
ndarray[Any, Any] | Series[Any] | Index[Any] | None"  [arg-type]
file.py:7: error: Argument "value" to "insert" of "DataFrame" has incompatible type "floating[_64Bit]";
 expected "str | bytes | date | datetime | timedelta | <7 more items> | complex | Sequence[Any] |
 ndarray[Any, Any] | Series[Any] | Index[Any] | None"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 30, 2024

I think if we add np.floating to IndexIterScalar in _typing.pyi, that should address this issue.

PR with tests welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFrame DataFrame data structure
Projects
None yet
Development

No branches or pull requests

3 participants