Replies: 3 comments
-
I just tried your example on what is currently in |
Beta Was this translation helpful? Give feedback.
0 replies
-
You are right, the example doesn't work, my bad. This example does work though, and the same question still applies. data: pd.DataFrame | pd.Series = pd.Series()
pd.concat([pd.DataFrame(), data]) returns
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I created an issue #879 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
When running this code with
mypy
(note I am using the code inmain
, which acceptsNone
as type for pd.concat):it returns this error:
error: List item 1 has incompatible type "DataFrame | None"; expected "DataFrame" [list-item]
Now, I understand where the error comes from, the overloaded method has type
Iterable[DataFrame | None]
anddata
has typeUnion[DataFrame, None]
instead of onlyDataFrame
orNone
, hence it's incompatible. But common sense says this should work, and indeed, at runtime the code works just fine. Is there a clean/standard way of solving this error onmypy
?I understand I could just write an if-else statement to check if data is None, but I am looking for a more structural solution that could solve other similar issues, for example when
data
can also be apd.Series
, e.g.,data: pd.Series | pd.DataFrame | None
.Thank you.
Beta Was this translation helpful? Give feedback.
All reactions