Description
- 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.
Code Sample, a copy-pastable example
import pandas as pd
filepath = r"<path where the file should be stored>"
data = [1,2,None,None,None,3]
sparse_data = pd.arrays.SparseArray(data)
df = pd.DataFrame(dict(a=sparse_data))
df.to_hdf(filepath, "data", format="t", data_columns=True)
>>> File "...\lib\site-packages\pandas\io\pytables.py", line 2323, in _get_atom
>>> itemsize = dtype.itemsize # type: ignore[attr-defined]
>>> AttributeError: 'SparseDtype' object has no attribute 'itemsize'
Problem description
the code-example tells it all... saving a sparse-DataFrame to HDF raises an error
Expected Output
a properly exported DataFrame
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17763
machine : AMD64
processor : AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en
LOCALE : German_Austria.1252
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.1
setuptools : 49.6.0.post20210108
Cython : None
pytest : None
hypothesis : None
sphinx : 4.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.24.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.06.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : 0.17.0
xlrd : None
xlwt : None
numba : None