Describe the bug
The way that ty treats int and float can cause more issues in the future, we can annotate as float and ty will see it as int | float.
See https://docs.astral.sh/ty/reference/typing-faq/#why-does-ty-show-int-float-when-i-annotate-something-as-float
Just wanted to open the discussion, haven't thought about the issue yet but worth keeping in the back of our mind.
To Reproduce
- Provide a minimal runnable
pandas example that is not properly checked by the stubs.
- Indicate which type checker you are using (
mypy or pyright).
- Show the error message received from that type checker while checking your example.
from dataclasses import dataclass
import pandas as pd
from typing_extensions import reveal_type
@dataclass
class A:
a: float
some_a = A(2.0)
reveal_type(some_a.a)
df = pd.Series([1.0, 3.0, 4.0], index=["a", "b", "c"], dtype=float)
reveal_type(A.a)
df.iloc[0] = A.a
info[revealed-type]: Revealed type
--> test_ty.py:13:13
|
12 | some_a = A(2.0)
13 | reveal_type(some_a.a)
| ^^^^^^^^ `int | float`
14 |
15 | df = pd.Series([1.0, 3.0, 4.0], index=["a", "b", "c"], dtype=float)
|
info[revealed-type]: Revealed type
--> test_ty.py:16:13
|
15 | df = pd.Series([1.0, 3.0, 4.0], index=["a", "b", "c"], dtype=float)
16 | reveal_type(A.a)
| ^^^ `int | float`
17 | df.iloc[0] = A.a
|
error[invalid-assignment]: Invalid subscript assignment with key of type `Literal[0]` and value of type `int | float` on object of type `_iLocIndexerSeries[float]`
--> test_ty.py:17:1
|
15 | df = pd.Series([1.0, 3.0, 4.0], index=["a", "b", "c"], dtype=float)
16 | reveal_type(A.a)
17 | df.iloc[0] = A.a
| ^^^^^^^^^^^^^^^^
|
info: rule `invalid-assignment` is enabled by default
Please complete the following information:
- OS: [e.g. Windows, Linux, MacOS] MacOS
- OS Version [e.g. 22] 26.0.1
- python version 3.14
- version of type checker ty 0.0.4
- version of installed
pandas-stubs main
Additional context
Add any other context about the problem here.
Describe the bug
The way that
tytreats int and float can cause more issues in the future, we can annotate asfloatandtywill see it asint | float.See https://docs.astral.sh/ty/reference/typing-faq/#why-does-ty-show-int-float-when-i-annotate-something-as-float
Just wanted to open the discussion, haven't thought about the issue yet but worth keeping in the back of our mind.
To Reproduce
pandasexample that is not properly checked by the stubs.mypyorpyright).Please complete the following information:
pandas-stubsmainAdditional context
Add any other context about the problem here.