Skip to content

Converting dtype of column from str to S not working on reassignment #15575

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
maxnoe opened this issue Mar 5, 2017 · 5 comments
Closed

Converting dtype of column from str to S not working on reassignment #15575

maxnoe opened this issue Mar 5, 2017 · 5 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request

Comments

@maxnoe
Copy link

maxnoe commented Mar 5, 2017

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({'a': ['Hello', 'World']})

df['a'] = df['a'].astype('S')
df['b'] = df['a'].astype('S')

print(df.dtypes)

Output is:

a    object
b       |S5
dtype: object

Problem description

The new column has the correct dtype of numpy byte string, the old column no contains
the new values but still has dtype object.

Expected Output

Both columns should have dtype 'S'

Output of pd.show_versions()

import pandas as pd

df = pd.DataFrame({'a': ['Hello', 'World']})

df['a'] = df['a'].astype('S')
df['b'] = df['a'].astype('S')

print(df.dtypes)

@jreback
Copy link
Contributor

jreback commented Mar 5, 2017

dupe of #12857

an easy fix actually, these should be converted to object (never a fixed-width string/bytes which are not supported)

@jreback jreback closed this as completed Mar 5, 2017
@jreback jreback added 2/3 Compat Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request labels Mar 5, 2017
@jreback jreback added this to the No action milestone Mar 5, 2017
@maxnoe
Copy link
Author

maxnoe commented Mar 5, 2017

So you say this is intended behaviour and not converting to object on the new assignment is the bug?

@jreback
Copy link
Contributor

jreback commented Mar 5, 2017

yes, this should be object dtype. see the duplicate issue.

@maxnoe
Copy link
Author

maxnoe commented Mar 5, 2017

I think you should leave it to the user. If the user wants to do astype('S') that's pretty specific. Why force using object?

@jreback
Copy link
Contributor

jreback commented Mar 5, 2017

fixed width types for strings are not supported and don't offer any advantages except more complexity - this might change at some point but this is how it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants