#394: Use Union[List[Column], List[str]] for Select #395
#394: Use Union[List[Column], List[str]] for Select #395
Conversation
c27ee8e
to
bf7fcb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you work @qudade.
Unfortunately, this is not going to work. In fact Spark is very specific about types here, and the only support collection is list
.
Sequence
would type check for all kind of different types, like
>>> isinstance(range(10), Sequence)
True
>>> isinstance((), Sequence)
True
which are clearly not supported on runtime.
If you want to address this particular scenario you should use Union[List[Column], List[str]]
, i.e.
def select(self, __cols: Union[List[Column], List[str]]) -> DataFrame: ...
though it should probably cover other cases with similar signature.
as @zero323 pointed out in zero323#395 (review), we can use only List, not Sequence
That looks much better. Would you mind adding data tests for this? |
@zero323 sure, I'll try to add some tests next week. Is there some information how to run the tests? (simply calling |
Thanks.
You'll have to add annotations directory to your Line 17 in c3e949c
|
as @zero323 pointed out in zero323#395 (review), we can use only List, not Sequence (as originally suggested by mypy)
b824d80
to
270a9c3
Compare
as @zero323 pointed out in zero323#395 (review), we can use only List, not Sequence (as originally suggested by mypy)
270a9c3
to
48c60e9
Compare
Merged to master, thank you. |
as @zero323 pointed out in #395 (review), we can use only List, not Sequence (as originally suggested by mypy) Co-authored-by: Maciej <zero323@users.noreply.github.com>
we can use only List, not Sequence (as originally suggested by mypy) Co-authored-by: Maciej <zero323@users.noreply.github.com>
Passing a
List[str]
to select raises a mypy warning, similar forList[Column]
. We change the type fromList[Union[Column, str]]
toUnion[List[Column], List[str]]
.Fixes #394 .