-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
shouldn't pandas.Index.tolist convert from numpy datatypes to native Python datatypes? #12715
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
Comments
your patch won't do anything - you still end up with int64s |
Sorry to disagree, but I did test that patch and it does work. Index.values is a numpy array, so it use tolist on that which DOES convert to python-native dtypes (which is the reason why I think it would be preferable that Index.tolist would do it too). |
|
Something like this would work. Though I would actually write in cython to avoid any perf issues. Of course need to see where this is actually used. Note not touching things like
|
this is a dupe of #10904 . so if you'd like to submit a pull-request, so it with that issue number. thanks! |
@jreback I think you were missing the
But, @gdementen this patch won't work for all dtypes (the pandas-specific I mean, eg Timestamp) |
@jorisvandenbossche right! actually mixed dtypes are ok (as they are
note that this would have to address both Further this actually will require a bit of testing, e.g. going thru all the dtypes to make sure conversions are handled). |
I was about to show you like @jorisvandenbossche did when Github crashed on me (site unavailable for a few minutes). I don't see this is as a duplicate given that these are two different classes we speak about and which do not inherit from each other, but you are the maintainers, so nevermind. I spent enough time on this already, and it will apparently be easier to fix downstream. |
@gdementen see my comment above. I would accept a general fix, so these issues are exactly the same. An Generally fixing upstream in a good idea, depends on the complexity. Here its straightforward, so if you have the time, pls submit a PR. |
I know about upstream. I maintain a few projects myself. But sorry, the effort/usefulness_for_my_employer ratio is too high in this case and I am running out of time. PS: sorry if this whole conversation comes out as unfriendly (I am in an awful mood these days -- I work in Brussels) |
@gdementen no worries and be safe! |
I wonder if it wouldn't be better/less surprising if Index.tolist did that conversion. FWIW, I was bitten by it via xlwings which tries to send an index values to Excel via COM by using index.tolist() and since the COM layer only handles basic Python types, it breaks. The patch seems trivial (I can submit a PR if you like), but I don't know whether you'd accept that, nor if it would have any implications.
FWIW, it seems to be related to #10904.
Code Sample, a copy-pastable example if possible
Expected Output
<class 'int'>
output of
pd.show_versions()
python: 3.5.1
pandas: 0.18.0
numpy: 1.10.4
The text was updated successfully, but these errors were encountered: