-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pivot broken on the latest version 1.1.0 #35785
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
Thanks @WindSoilder for the report. can confirm that this is a regression in #30928 cc @charlesdong1991 11f1500 is the first bad commit
|
this may have accidentally worked before but is incorrect index must be a list of column labels not an index of values |
emm, thanks for reporting @WindSoilder, and indeed it is a behavior change from the previous version. However, I am not very sure the previous behavior is correct given the documentation of So the input for Alternatively, if you would like to still get the result, you could either reset index to make # solution 1
df.reset_index().pivot(index='date', columns='col1')
# solution 2
df.pivot(columns='col1') |
Thnaks @charlesdong1991 and @jreback for looking at this. can this be closed? |
@simonjayhawkins @jreback I think it can be closed from a bug-reporting perspective. However, I am not sure if a better error reporting message is preferred (and it might be slightly better if we do this check right at the top of the function)? Or a similar issue related test can be added to the tests? |
yeah it's likely not easy to actually give a better message because you can pass an Index if labels (though not very likely) but i suppose that you could catch the KeyError and enhance it to say - did you pass a list or label to pivot and not the index itself |
Thanks @charlesdong1991 @simonjayhawkins @jreback for quickly looking into this :) I will change my code to fit this behavior. |
Can i take it? |
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
Problem description
The exmple code raise a
KeyError
:It works on version
1.0.5
Expected Output
The output is something like this in version

1.0.5
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.7.7.final.0
python-bits : 64
OS : Darwin
OS-release : 19.4.0
Version : Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
pandas : 1.1.0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.0.post20200616
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 0.10.0
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.18
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: