Skip to content

Series.where return unmodified series in upcasting corner case #3971

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
dalejung opened this issue Jun 20, 2013 · 4 comments
Closed

Series.where return unmodified series in upcasting corner case #3971

dalejung opened this issue Jun 20, 2013 · 4 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@dalejung
Copy link
Contributor

import pandas as pd
import numpy as np
s = pd.Series(range(10))
s.where(s > 4, np.array([np.nan]))

Out[4]:
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: int64

The culprit is that if upcast is required, ser doesn't get changed in the com call. Since we're making a copy of self anyways, shouldn't we always pass in change?

        change = ser if inplace else None
        com._maybe_upcast_putmask(ser,~cond,other,change=change)

I didn't hit this organically and I'm assuming it's a fairly contrived example. Was just reading code and found this.

@jreback
Copy link
Contributor

jreback commented Jun 20, 2013

this is related to this (sort of): #3217

@jreback
Copy link
Contributor

jreback commented Jun 20, 2013

fyi, this is equivalent to doing:

s[s>4] = np.nan

@dalejung
Copy link
Contributor Author

yea, it's not something I'd likely run across. I was actually planning to use com._maybe_upcast_putmask, saw its behavior, went to see how it was used, and then couldn't figure out how the quoted lines form Series.where would return the correct results when upcasting and inplace=False.

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

closing as fixed in master

@jreback jreback closed this as completed Sep 22, 2013
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

No branches or pull requests

2 participants