Skip to content

BUG: where incorrectly coerces to str #9280

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
sinhrks opened this issue Jan 17, 2015 · 1 comment · Fixed by #9283
Closed

BUG: where incorrectly coerces to str #9280

sinhrks opened this issue Jan 17, 2015 · 1 comment · Fixed by #9283
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jan 17, 2015

Replacing some numeric values using where affects to dtype unrelated to the condition.

s = pd.Series(np.random.randn(5))
u = s.where(s<0, 'X', axis=1)
u
#0     -1.01421184508
#1                  X
#2                  X
#3    -0.228117839063
#4    -0.393903873887
# dtype: object

The result looks OK, but internally coerced to all str.

u.apply(type)
#0    <type 'str'>
#1    <type 'str'>
#2    <type 'str'>
#3    <type 'str'>
#4    <type 'str'>
# dtype: object
@sinhrks
Copy link
Member Author

sinhrks commented Jan 17, 2015

This seems to occur when data passed as str dtype because of numpy spec. I'll fix this if this is unintended.

Also, found different error.

w = s.where(s>1, ['A', 'B', 'C', 'D', 'E'])
# ValueError: invalid literal for long() with base 10: 'A'

w = s.where(s>1, np.array(['A', 'B', 'C', 'D', 'E']))
# ValueError: invalid literal for long() with base 10: 'A'

@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Bug labels Jan 17, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 17, 2015
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants