Skip to content

BUG: pd.concat returns empty series if called on mixture of empty and non-empty series #18187

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
SmokinCaterpillar opened this issue Nov 9, 2017 · 1 comment · Fixed by #18191
Labels
Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@SmokinCaterpillar
Copy link
Contributor

Code Sample

import pandas as pd

s1 = pd.Series([1])
s2 = pd.Series([])

pd.concat([s1, s2])

returns an empty series Series([], dtype: int64).

Problem description

Concatenating an non-empty and empty series returns an empty series.
If this is supposed to be the intended behavior, it is very counterintuitive. I would rather expect that the
result of pd.concat([s1, s2]) is simply equal to s1. In fact, this used to be the behavior in older versions like 0.20.3.

Btw, I stumbled upon this error while I was trying to fix #18178. Out of curiosity I checked what happens in case of concatenating non-empty and empty series instead of frames.

Expected Output

Series equal to s1, i.e. repr(pd.concat([s1, s2])) returns '0 1\ndtype: int64'.

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: None
numpy: 1.13.3
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Nov 9, 2017
@jorisvandenbossche jorisvandenbossche added this to the 0.21.1 milestone Nov 9, 2017
@jorisvandenbossche
Copy link
Member

Yes, this is certainly a bug, so a regression from 0.20.3. Probably it has the same cause as #18178

SmokinCaterpillar pushed a commit to flix-tech/pandas that referenced this issue Nov 9, 2017
…of empty RangeIndex

The `_concat_rangeindex_same_dtype` now keeps track of the last non-empty RangeIndex to extract the new stop value.

This fixes two issues with concatenating non-empty and empty DataFrames and Series.

Two regression tests were added as well.
No-Stream pushed a commit to No-Stream/pandas that referenced this issue Nov 28, 2017
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this issue Dec 8, 2017
TomAugspurger pushed a commit that referenced this issue Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants