Skip to content

ENH: Add support for nullable integer columns to StataWriter #40855

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

Closed
kkwaiser opened this issue Apr 9, 2021 · 1 comment · Fixed by #42565
Closed

ENH: Add support for nullable integer columns to StataWriter #40855

kkwaiser opened this issue Apr 9, 2021 · 1 comment · Fixed by #42565
Labels
Enhancement IO Stata read_stata, to_stata NA - MaskedArrays Related to pd.NA and nullable extension arrays
Milestone

Comments

@kkwaiser
Copy link

kkwaiser commented Apr 9, 2021

When attempting to export a dataframe to a Stata data file, I hit the following error due to my dataframe including variables of the Int64 dtype.

import pandas as pd

# CREATE DATAFRAME
s1 = pd.Series(2**33, dtype='Int64')
s2 = pd.Series("ABC", dtype=object)
df = pd.DataFrame({'col1': s1, 'col2': s2})

df = df.append({'col1': None, 'col2': "DEF"}, ignore_index=True)

# EXPORT TO STATA
df.to_stata('df.dta', version=117)

Error message:

NotImplementedError: Data type Int64 not supported.

My expectation is columns of dtype Int64 (i.e., a nullible INT) would end up as byte, int or float in the dta file depending on values therein.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.8.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.14393
machine : AMD64
processor : Intel64 Family 6 Model 61 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United States.1252

pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : None
pytest : None
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.3
sqlalchemy : 1.3.20
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None

@kkwaiser kkwaiser added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 9, 2021
@jbrockmendel jbrockmendel added IO Stata read_stata, to_stata NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2021
@bashtage bashtage changed the title pd.to_stata: Data type Int64 not supported ENH: Add support for nullable integer columns to StataWriter May 18, 2021
@bashtage bashtage added Enhancement and removed Bug labels May 18, 2021
@bashtage
Copy link
Contributor

I've relabeled this as an enhancement. Stata supports nullable columns with any underlying dtype. Fairly straightforward enhancement request, and reasonable.

bashtage added a commit to bashtage/pandas that referenced this issue Jul 16, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 16, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 16, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 19, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 19, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 19, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 19, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 21, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Jul 29, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Aug 30, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Sep 1, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Sep 10, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Sep 13, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
@jreback jreback added this to the 1.4 milestone Sep 14, 2021
bashtage added a commit to bashtage/pandas that referenced this issue Sep 14, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Sep 14, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
bashtage added a commit to bashtage/pandas that referenced this issue Sep 14, 2021
Add code that allows nullable arrays to be written

closes pandas-dev#40855
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Stata read_stata, to_stata NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants