Skip to content

BUG: Column 'Int8Dtype' casted to 'object' type when melted #41570

Closed
@etiennekintzler

Description

@etiennekintzler
  • [x ] I have checked that this issue has not already been reported.

  • [ x] 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.


Pandas's dtype Int8Dtype is converted to object when melted.

Code Sample, a copy-pastable example

df = pd.DataFrame({"a": pd.Series([1, 2], dtype=pd.Int8Dtype())})
melted = df.melt()
print(melted.dtypes)

Problem description

When melted, the Int8 column is casted to object type.

Expected Output

melted.dtypes should return:

variable    object
value       Int8
dtype: object

Output of ``pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.7.0.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-143-generic
Version : #147-Ubuntu SMP Wed Apr 14 16:10:11 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.5
numpy : 1.19.4
pytz : 2020.5
dateutil : 2.8.1
pip : 21.0.1
setuptools : 54.1.2
Cython : None
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : 1.0.8
s3fs : None
scipy : 1.5.4
sqlalchemy : 1.3.22
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 2.0.1
xlwt : None
numba : 0.53.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.NA - MaskedArraysRelated to pd.NA and nullable extension arraysReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions