-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.apply returns inconsistent index depending on applied function's return type #35683
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
Hello, @BobbyBlue42 , and thanks for the PR! Confirmed this behavior for the head of the master branch. |
Thanks for checking that for me, @AlexKirko In my case, this came up when attempting to find date/datetime formats of any string columns in the While the timestamp use case might not be particularly common, I think that in general attempting to iterate over the original |
I'll mark this as a regression for now pending further investigation/discussion cc @jbrockmendel the Exception case arises from #34909 (not checked the others) 91802a9 is the first bad commit
|
DataFrame.apply makes a best-guess as to whether it is looking at a reduction or not. A case with an always-empty listlike result is a sharp corner.
|
heads up: associated PR moved off 1.1.1 |
Using
Also, PR #35777 mentions this issue in the whatsnew; can this issue be closed? |
moved off 1.1.2 milestone (scheduled for this week) as no PRs to fix in the pipeline and pending further discussion |
moved off 1.1.3 milestone (overdue) pending further discussion |
@jbrockmendel I think your PR linked above closes out this issue, is that correct? |
#35777 fixed the definitely-wrong behavior where the result_type keyword was not respected, doesn't change the not-clearly-wrong behavior in the OP (which Im ok with calling not-a-bug) |
moved off 1.1.4 milestone (scheduled for release tomorrow) as no PRs to fix in the pipeline |
+1 on closing. The edge case has two valid interpretations, which ever we default to will be confusing to someone. The argument |
Code Sample
With pandas 1.1.0, this outputs:
Problem description
As shown above, when different data types are turned by the applied function, the index of the result is changed. From what I have seen, this is neither documented behaviour, nor is it consistent with itself. Additionally, in previous versions of pandas,
apply
worked differently, as shown below.Expected Output
This is the output when running with pandas 1.0.5 and pandas 1.0.4, and is what I would expect:
Output of
pd.show_versions()
Environment with pandas 1.1.0:
INSTALLED VERSIONS
commit : d9fff27
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-42-generic
Version : #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_NZ.UTF-8
LOCALE : en_NZ.UTF-8
pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 39.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
Environment with pandas 1.0.5:
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-42-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_NZ.UTF-8
LOCALE : en_NZ.UTF-8
pandas : 1.0.5
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 39.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : 0.4.2
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: