<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np

fill_value = 0 
#fill_value = np.nan

df0 = pd.DataFrame({'A': [1, fill_value, fill_value]})
df1 = pd.DataFrame({'B': ['a','b','c']})

c = pd.concat([df0, df1], axis=1)
print(c) # &gt;&gt;&gt; OK
print(c['A']) # &gt;&gt;&gt; OK
print(c['B']) # &gt;&gt;&gt; OK

#========================
print(&quot;=====================&quot;)
df0_s = df0.to_sparse(fill_value = fill_value)
c = pd.concat([df0_s, df1], axis=1)
print(c) # &gt;&gt;&gt; OK
print(c['A']) # &gt;&gt;&gt; OK
print(c['B']) # &gt;&gt;&gt; ERROR: 'IntBlock' object has no attribute 'sp_index'"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">fill_value</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span> 
<span class="pl-c">#fill_value = np.nan</span>

<span class="pl-s1">df0</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'A'</span>: [<span class="pl-c1">1</span>, <span class="pl-s1">fill_value</span>, <span class="pl-s1">fill_value</span>]})
<span class="pl-s1">df1</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'B'</span>: [<span class="pl-s">'a'</span>,<span class="pl-s">'b'</span>,<span class="pl-s">'c'</span>]})

<span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">df0</span>, <span class="pl-s1">df1</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-en">print</span>(<span class="pl-s1">c</span>) <span class="pl-c"># &gt;&gt;&gt; OK</span>
<span class="pl-en">print</span>(<span class="pl-s1">c</span>[<span class="pl-s">'A'</span>]) <span class="pl-c"># &gt;&gt;&gt; OK</span>
<span class="pl-en">print</span>(<span class="pl-s1">c</span>[<span class="pl-s">'B'</span>]) <span class="pl-c"># &gt;&gt;&gt; OK</span>

<span class="pl-c">#========================</span>
<span class="pl-en">print</span>(<span class="pl-s">"====================="</span>)
<span class="pl-s1">df0_s</span> <span class="pl-c1">=</span> <span class="pl-s1">df0</span>.<span class="pl-en">to_sparse</span>(<span class="pl-s1">fill_value</span> <span class="pl-c1">=</span> <span class="pl-s1">fill_value</span>)
<span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">df0_s</span>, <span class="pl-s1">df1</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-en">print</span>(<span class="pl-s1">c</span>) <span class="pl-c"># &gt;&gt;&gt; OK</span>
<span class="pl-en">print</span>(<span class="pl-s1">c</span>[<span class="pl-s">'A'</span>]) <span class="pl-c"># &gt;&gt;&gt; OK</span>
<span class="pl-en">print</span>(<span class="pl-s1">c</span>[<span class="pl-s">'B'</span>]) <span class="pl-c"># &gt;&gt;&gt; ERROR: 'IntBlock' object has no attribute 'sp_index'</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The above code fails, when using mixed type data on segmenting the frame.<br>
A possible work-around is to recast the resulting sparse dataframe to a dense data frame via<br>
c_new = pd.DataFrame(c)</p>
<p dir="auto">At the bootom of this it seems that <code class="notranslate">pandas.concat</code> always uses the highest class object in the to catenate list, e.g. here the SparseDataFrame, to store teh resulting values in. This effectively works deep, below, however, the on surface interfaces are kind of blown out if the data contained is not as expected.<br>
This might be a very similar issue as <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="277484564" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/18551" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/18551/hovercard" href="https://github.com/pandas-dev/pandas/issues/18551">#18551</a> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="277484564" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/18551" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/18551/hovercard" href="https://github.com/pandas-dev/pandas/issues/18551">#18551</a>)</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">well, hard to say if SparseDataFrames are to handle mixed type data (possibly keeping some of the columns sparse, other dense), or if <code class="notranslate">pd.concat</code> should fall back to a dense DataFrame here. Anyhow, the issue should be fixed one way or another,</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.1.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.21.0<br>
pytest: 3.0.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.13.3<br>
scipy: 0.19.1<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.2.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.999<br>
sqlalchemy: 1.1.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="215309477" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/15737" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/15737/hovercard" href="https://github.com/pandas-dev/pandas/issues/15737">#15737</a></p>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd

pd.concat([pd.DataFrame([0.0]), pd.SparseDataFrame([0.0])], axis=1).isnull() 
pd.concat([pd.DataFrame([0.0]), pd.SparseDataFrame([0.0])], axis=1).density
pd.concat([pd.DataFrame([0.0], columns=['A']), pd.SparseDataFrame([0.0])], axis=1)['A'] 
pd.concat([pd.DataFrame([0.0], columns=['A']), pd.SparseDataFrame([0.0])], axis=1).iloc[0,0]
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([<span class="pl-c1">0.0</span>]), <span class="pl-s1">pd</span>.<span class="pl-v">SparseDataFrame</span>([<span class="pl-c1">0.0</span>])], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-en">isnull</span>() 
<span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([<span class="pl-c1">0.0</span>]), <span class="pl-s1">pd</span>.<span class="pl-v">SparseDataFrame</span>([<span class="pl-c1">0.0</span>])], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-s1">density</span>
<span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([<span class="pl-c1">0.0</span>], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'A'</span>]), <span class="pl-s1">pd</span>.<span class="pl-v">SparseDataFrame</span>([<span class="pl-c1">0.0</span>])], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)[<span class="pl-s">'A'</span>] 
<span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([<span class="pl-c1">0.0</span>], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'A'</span>]), <span class="pl-s1">pd</span>.<span class="pl-v">SparseDataFrame</span>([<span class="pl-c1">0.0</span>])], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-s1">iloc</span>[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>]</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Each of the above lines generates an error when the dataframes are of mixed sparsity, but would succeed if both dataframes were dense or both were sparse.  This means that we can't seamlessly swap sparse dataframes for dense ones without knowing how they'll be used downstream.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Each line does not generate an error.</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
##INSTALLED VERSIONS
<p dir="auto">commit: None<br>
python: 3.5.2.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.20.2<br>
pytest: 2.9.2<br>
pip: 8.1.2<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.13.0<br>
scipy: 0.18.1<br>
xarray: None<br>
IPython: 5.1.0<br>
sphinx: 1.4.6<br>
patsy: 0.4.1<br>
dateutil: 2.5.3<br>
pytz: 2016.6.1<br>
blosc: None<br>
bottleneck: 1.1.0<br>
tables: 3.2.2<br>
numexpr: 2.6.1<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: 2.3.2<br>
xlrd: 1.0.0<br>
xlwt: 1.1.2<br>
xlsxwriter: 0.9.3<br>
lxml: 3.6.4<br>
bs4: 4.5.1<br>
html5lib: None<br>
sqlalchemy: 1.0.13<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: 0.4.0</p>
</details>