ENH: support nullable dtypes in get_dummies · Issue #32430 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd
series = pd.Series(list('AA')) col = pd.get_dummies(series, dtype='UInt8').A
assert col.dtype.name == 'UInt8' # Actual: np.uint8
Problem description
In get_dummies
, dtype strings of "Int64", etc., are ignored in favor of their non-nullable Numpy equivalents.
There's a few other places that could cause this bug, but I haven't checked public API:
.core.reshape.reshape._Unstacker.get_new_values
.core.dtypes.cast.maybe_downcast_to_dtype
.core.dtypes.cast.maybe_downcast_numeric
Expected Output
The dtype of such a call should be the Nullable type.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None