-
-
Notifications
You must be signed in to change notification settings - Fork 141
error: No overload variant of "replace" of "DataFrame" matches argument types "str", "NAType" [call-overload] #262
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
Comments
Have to add |
Maybe |
We'd have to check in all the uses of |
It might make sense to also introduce both a class Series(Generic[ScalarType]):
def replace(self, to_replace: ScalarType, value: NAType) -> Series[NullableScalarType]: However, I am not quite sure how to actually correctly implement this without the tedious @overload
def replace(self, to_replace: np.float32, value: NAType) -> Series[Float32Dtype]: ...
@overload
def replace(self, to_replace: np.float64, value: NAType) -> Series[Float64Dtype]: ...
@overload
def replace(self, to_replace: np.int32, value: NAType) -> Series[Int32Dtype]: ...
@overload
def replace(self, to_replace: np.int64, value: NAType) -> Series[Int64Dtype]: ...
@overload
def replace(self, to_replace: np.bool_, value: NAType) -> Series[BooleanDtype]: ... Because Besides, it seems that |
I'm open to solutions that are incremental, and don't introduce too much complexity, and don't make the corresponding stubs too wide. Making changes to how the generic aspects of
Are you saying this is an issue with the stubs or with pandas itself? Always open to having issues created in either project! |
@Dr-Irv It's an issue both with import pandas
x = pandas.Series([1.0, 3.1, float('nan')])
print(x.dtype)
y = x.replace(float('nan'), pandas.NA)
print(y.dtype) # object ✘ (expected: Float64)
z = x.replace(1, 1+1j)
print(z.dtype) # complex128 ✔ |
What you are seeing is that promotion is using NumPy rules. Seems like promotion from numpy dtypes to extension dtypes is not implemented, or at least not complete. This isn't a surprise as it is pretty hard. |
So given the response to pandas-dev/pandas#48409 , I think the best we can support here is allowing |
The text was updated successfully, but these errors were encountered: