Skip to content
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

BUG: DataFrame.explode is failing on scalar int value. #43314

Closed
2 of 3 tasks
galipremsagar opened this issue Aug 30, 2021 · 2 comments · Fixed by #43802
Closed
2 of 3 tasks

BUG: DataFrame.explode is failing on scalar int value. #43314

galipremsagar opened this issue Aug 30, 2021 · 2 comments · Fixed by #43802
Labels
Bug Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@galipremsagar
Copy link

  • 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

>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame({0: [[0, 1, 2], 'foo', [], [3, 4]],
...                    1: 1,
...                    2: [['a', 'b', 'c'], np.nan, [], ['d', 'e']]})
>>> df
           0  1          2
0  [0, 1, 2]  1  [a, b, c]
1        foo  1        NaN
2         []  1         []
3     [3, 4]  1     [d, e]
>>> df.columns
Int64Index([0, 1, 2], dtype='int64')
>>> df.explode(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pgali/anaconda3/envs/cudf_dev/lib/python3.8/site-packages/pandas/core/frame.py", line 8229, in explode
    assert isinstance(column, (str, tuple))
AssertionError
>>> df.explode([0])
     0  1          2
0    0  1  [a, b, c]
0    1  1  [a, b, c]
0    2  1  [a, b, c]
1  foo  1        NaN
2  NaN  1         []
3    3  1     [d, e]
3    4  1     [d, e]
>>> 

Problem description

Looks like passing a scalar int to column is causing a failure in DataFrame.explode, but passing a list of int's is working.

Expected Output

>>> df.explode(0)
     0  1          2
0    0  1  [a, b, c]
0    1  1  [a, b, c]
0    2  1  [a, b, c]
1  foo  1        NaN
2  NaN  1         []
3    3  1     [d, e]
3    4  1     [d, e]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-27-generic
Version : #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.4.0
Cython : 0.29.24
pytest : 6.2.4
hypothesis : 6.17.2
sphinx : 4.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.27.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2021
@galipremsagar galipremsagar changed the title BUG: DataFrame.explode is failing on scalar int value. BUG: DataFrame.explode is failing on scalar int value. Aug 30, 2021
@jreback jreback added this to the 1.4 milestone Aug 31, 2021
@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Aug 31, 2021
@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Aug 31, 2021
@simonjayhawkins simonjayhawkins modified the milestones: 1.4, 1.3.3 Aug 31, 2021
@simonjayhawkins
Copy link
Member

Thanks @galipremsagar for the report.

Looks like passing a scalar int to column is causing a failure in DataFrame.explode, but passing a list of int's is working.

1.2.5 was giving the expected output.

@simonjayhawkins
Copy link
Member

first bad commit: [41a94b0] EHN: multi-column explode (#39240) (#40770)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
3 participants