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: pd.concat returns empty series if called on mixture of empty and non-empty series #18187

Closed
SmokinCaterpillar opened this Issue Nov 9, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@SmokinCaterpillar
Contributor

SmokinCaterpillar commented Nov 9, 2017

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

This comment has been minimized.

Show comment
Hide comment
@jorisvandenbossche

jorisvandenbossche Nov 9, 2017

Member

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

Member

jorisvandenbossche commented Nov 9, 2017

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

SmokinCaterpillar added a commit to flix-tech/pandas that referenced this issue Nov 9, 2017

Fix for pandas-dev#18178 and pandas-dev#18187 by changing the concat …
…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.

jreback added a commit that referenced this issue Nov 10, 2017

No-Stream added a commit to No-Stream/pandas that referenced this issue Nov 28, 2017

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Dec 8, 2017

TomAugspurger added 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