Skip to content
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

df.to_stata doesn't handle boolean columns #7097

Closed
puterleat opened this issue May 11, 2014 · 7 comments
Closed

df.to_stata doesn't handle boolean columns #7097

puterleat opened this issue May 11, 2014 · 7 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement IO Stata read_stata, to_stata
Milestone

Comments

@puterleat
Copy link

I'd expected this to generate a row of 1's and 0's in the dta file...

DataFrame([True, False]).to_stata('test.dta')

But it generates the following error:

sbox/lib/python2.7/site-packages/pandas/io/stata.pyc in _dtype_to_stata_type(dtype)
884 else: # pragma : no cover
885 raise ValueError("Data type %s not currently understood. "
--> 886 "Please report an error to the developers." % dtype)
887
888

ValueError: Data type bool not currently understood. Please report an error to the developers.

@jreback jreback added this to the 0.15.0 milestone May 11, 2014
@jreback
Copy link
Contributor

jreback commented May 11, 2014

its straightforward to do this enhancement, would welcome a pull-request.

@jreback
Copy link
Contributor

jreback commented May 11, 2014

you can always df[[boolean_columns]] = df[[boolean_columns]].astype(int) to get the desired effect (as a work-around)

@puterleat
Copy link
Author

Ah - many thanks for the workaround. Just spotted that datetime64[ns] is also not currently understood.

@jreback
Copy link
Contributor

jreback commented May 11, 2014

datetimens64[ns] works just fine in master/0.14 and should in 0.13.1.

@puterleat
Copy link
Author

EDIT:
I've just realised that the convert_dates parameter solves the problem, although this isn't obvious from the error message thrown (which suggests contacting the developers...)

Perhaps dates without a conversion specified could throw a specific error requesting the convert_dates mapping be set?

@dmsul
Copy link

dmsul commented Jun 5, 2014

I just got this same error (0.14.0) for a uint16 dtype. Not sure if it's better to make an independent issue thread or post here. I'm new at this, apologies.

@jreback
Copy link
Contributor

jreback commented Jun 5, 2014

maybe post separate issues for the last 2 (error reporting for using convert_dates & the uint16 issue). and would appreciate pull-requests !

@jreback jreback added Stata and removed Data IO labels Jun 5, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Jul 10, 2014
bashtage added a commit to bashtage/pandas that referenced this issue Jul 15, 2014
Added support for uint (uint8, uint16 and uint32, but not uint64) and bool
datatypes in to_stata.   Added an explanation of supported data types in io.rst.
closes pandas-dev#7097 and closes pandas-dev#7365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement IO Stata read_stata, to_stata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants