Skip to content

Explode on identical index causes duplication #28005

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
mar-muel opened this issue Aug 18, 2019 · 2 comments · Fixed by #28010
Closed

Explode on identical index causes duplication #28005

mar-muel opened this issue Aug 18, 2019 · 2 comments · Fixed by #28010

Comments

@mar-muel
Copy link

Code Sample, a copy-pastable example if possible

>>> df = pd.DataFrame({'col': [['a', 'b'], ['c', 'd']]}, index=[0,0])
>>> df.explode('col')
  col
0   a
0   b
0   c
0   d
0   a
0   b
0   c
0   d

Problem description

I'm not sure if this is expected behaviour. But it took me slightly off guard when I had a datetime index with occasionally identical timestamps. This is the output I expected:

  col
0   a
0   b
0   c
0   d

Thanks for your work on pandas! Apologies if this is actually normal behaviour.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.7.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-139-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.14.3
pytz : 2018.9
dateutil : 2.8.0
pip : 19.0.2
setuptools : 40.8.0
Cython : None
pytest : 4.5.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.3.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.0.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@TomAugspurger
Copy link
Contributor

Hmm thanks for the report. Duplicating like this probably isn't deliberate...

@MarcoGorelli
Copy link
Member

Seems to only happen to frames (not series):

>>> pd.Series([[1,2], [3,4]], index=[0, 0]).to_frame('col').explode('col')
  col
0   1
0   2
0   3
0   4
0   1
0   2
0   3
0   4
>>> pd.Series([[1,2], [3,4]], index=[0, 0]).explode()
0    1
0    2
0    3
0    4
dtype: object

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.

3 participants