-
-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Describe the bug
Type checker error when converting the result of Series.var() (and other statistical methods) to float. The type checker reports that Scalar cannot be assigned to parameter x of type ConvertibleToFloat, even though this conversion works correctly at runtime.
To Reproduce
- Minimal runnable example:
import pandas as pd
s = pd.Series([1.0, 2.0, 3.0])
variance = float(s.var()) # Type error here-
Type checker:
pyright -
Error message:
Argument of type "Scalar" cannot be assigned to parameter "x" of type "ConvertibleToFloat" in function "__new__"
The same issue occurs with other statistical methods: .mean(), .std(), .median(), etc.
Please complete the following information:
- OS: AlmaLinux 9
- python version: 3.13.1
- version of type checker: pyright 1.1.407
- version of installed
pandas-stubs: 2.3.3.251201
Additional context
The code works correctly at runtime - Series.var() does return a numeric value that can be converted to float. The issue is that the return type is annotated as Scalar in the type stubs, which the type checker doesn't recognize as convertible to float. Current workaround is to use # type: ignore comments.