Skip to content

Conversation

@olgarithms
Copy link
Contributor

@MarcoGorelli
Copy link
Member

Nice one @olgarithms , thanks!

Could you also include a comment in which you show the output of something like #40860 (comment) ?

@olgarithms
Copy link
Contributor Author

Hmm, the output doesn't seem right but I am not very sure why..

# t.py

import pandas as pd

inplace: bool

reveal_type(pd.DataFrame([1,2,3]).drop_duplicates())
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(keep="last"))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(inplace=True))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(keep="last", inplace=True))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(inplace=False))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(keep="last", inplace=False))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).drop_duplicates(keep="last", inplace=inplace))
$ mypy t.py
t.py:7: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:8: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:9: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:10: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:11: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:12: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:13: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
t.py:14: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'

@MarcoGorelli
Copy link
Member

Perhaps try running mypy pandas again, and then mypy t.py?

@olgarithms
Copy link
Contributor Author

olgarithms commented Apr 11, 2021

Oops, my bad, I was using drop_duplicates from DataFrame.

The correct test:

# t.py

import pandas

inplace: bool

reveal_type(pandas.Series([1,2,3]).drop_duplicates())
reveal_type(pandas.Series([1,2,3]).drop_duplicates(keep="last"))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(inplace=True))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(keep="last", inplace=True))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(inplace=False))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(keep="last", inplace=False))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(inplace=inplace))
reveal_type(pandas.Series([1,2,3]).drop_duplicates(keep="last", inplace=inplace))
$ mypy t.py
t.py:7: note: Revealed type is 'pandas.core.series.Series'
t.py:8: note: Revealed type is 'pandas.core.series.Series'
t.py:9: note: Revealed type is 'None'
t.py:10: note: Revealed type is 'None'
t.py:11: note: Revealed type is 'pandas.core.series.Series'
t.py:12: note: Revealed type is 'pandas.core.series.Series'
t.py:13: note: Revealed type is 'Union[pandas.core.series.Series, None]'
t.py:14: note: Revealed type is 'Union[pandas.core.series.Series, None]'

@olgarithms olgarithms marked this pull request as ready for review April 11, 2021 21:45
@MarcoGorelli MarcoGorelli added the Typing type annotations, mypy/pyright type checking label Apr 12, 2021
@MarcoGorelli MarcoGorelli added this to the 1.3 milestone Apr 12, 2021
@MarcoGorelli
Copy link
Member

Nice work, thanks @olgarithms !

Oops, my bad, I was using drop_duplicates from DataFrame.

😆 no worries - though seeing as you're familiar with how to do this now, if you wanted to do the overloads DataFrame.drop_duplicates, that would be welcome! Else I'll open it up as an issue for others to take

@MarcoGorelli MarcoGorelli merged commit 735f40c into pandas-dev:master Apr 12, 2021
@olgarithms
Copy link
Contributor Author

Sure, I can take that one too :)

@olgarithms olgarithms deleted the overload-series-drop_duplicates branch May 11, 2021 08:27
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Typing type annotations, mypy/pyright type checking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants