Skip to content

BUG: wrong type hint for pandas.Series.droplevel #39907

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

Closed
2 of 3 tasks
sz-cgt opened this issue Feb 19, 2021 · 4 comments · Fixed by #39932
Closed
2 of 3 tasks

BUG: wrong type hint for pandas.Series.droplevel #39907

sz-cgt opened this issue Feb 19, 2021 · 4 comments · Fixed by #39932

Comments

@sz-cgt
Copy link

sz-cgt commented Feb 19, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

type(pandas.Series({("a", 1): 1, ("a", 2): 2, ("b", 1): 3, ("b", 4): 4}).droplevel(level=1))

Problem description

Both the type hint for pandas.Series.droplevel() and the documentation say the function returns a DataFrame.

However, it clearly returns a Series.

While not a Bug per se, this does violate the Law of Least Suprise

Output of pd.show_versions()

pandas.show_versions()

INSTALLED VERSIONS

commit : 7d32926
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.104-microsoft-standard
Version : #1 SMP Wed Feb 19 06:37:35 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.2
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 44.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 0.17.1
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@sz-cgt sz-cgt added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 19, 2021
@MarcoGorelli
Copy link
Member

Thanks @sz-cgt - looks like this docstring needs a substitution (see other methods in that file which have @doc), do you want to open a pull request to fix this? If so, here's the contributing guide

@MarcoGorelli MarcoGorelli added Docs good first issue and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 19, 2021
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Feb 20, 2021
@Muktan
Copy link
Contributor

Muktan commented Feb 20, 2021

@MarcoGorelli, I came up with a solution with docstring substitution as follows.

...
+@doc(klass=_shared_doc_kwargs["klass"])
    def droplevel(self: FrameOrSeries, level, axis=0) -> FrameOrSeries:
        """
        Return {klass} with requested index / column level(s) removed.
        ...

Is this the expected behavior:-
Screenshot from 2021-02-20 18-28-08

I am not sure if it is ok to have Series/DataFrame in Returns.

@MarcoGorelli
Copy link
Member

@Muktan looks fine to me (this method is marked @final so it can't be overridden anyway) - want to open a PR?

@Muktan
Copy link
Contributor

Muktan commented Feb 20, 2021

Will do it right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants